-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dust helpers empty on server side require #72
Comments
Looking at the code it seems broken in both 1.1.x and 1.2.x. It was returning object with helpers in 1.0.x. Are you sure this works in 1.1.x ? I will look into fixing this today or tomorrow. |
Yep, just double checked, I'm on 1.1.2 currently. |
I just gave this a try and I'm having trouble reproducing issue in 1.2.0. This is how I tested tihs:
The output I get is
Am I missing something? This is the code that makes sure
|
Removed all my modules and reinstalled, seems to be working now, glitch in the matrix :P |
Ok spoke too soon, so it seems like the helpers don't extend dust if required afterward anymore is the issue. But in the case of just requiring the helpers it does work.
|
|
Yep I know, but if you require dustjs-linkedin and then require dustjs-helpers you end up with empty helpers. |
whoops. sorry didn't read the whole issue. looking deeper. |
Confirmed... but this should work. It should be the same as 'https://github.com/umdjs/umd/blob/master/jqueryPluginCommonjs.js'. some temporary work arounds this is what our jasmine test runner is sort of doing... but it really shouldn't be. less verbose but probably even more fragile end of the day, this is a bug that we need to fix.
|
@jimmyhchan I'm not sure it's possible to have On the other hand having dust as a global variable works:
|
I actually have it as a global and not working for some reason. I was doing it in coffeescript as a one liner. global.dust = require('dustjs-linkedin') ; require('dustjs-helpers') But since the helpers return the dustjs object I've just changed it to simply global.dust = require('dustjs-helpers') But the first version should still work and extend the current dust object. |
I've updated node's spec runner to test this. See #73 Are there other scenarios that we need to consider? |
@kate2753 I wasn't suggested that we add dust as global. Our code should work regardless of what we name the output of Consider that this works:
|
@jimmyhchan I see what you mean by node caching require('dustjs-linkedin'). Now it makes sense how this should work with local variable (local variable would be a reference to dust object in require cache, require('dustjs-helpers') will update the same object that local variable is referencing). I'm confused now why defining global dust variable works. Travis build passed for #73 We use the same code in dustjs-helpers as in your example. I'm wondering why it does not work with local variable:
|
@kate2753 found it. The last line of dust helpers
should be
if we want to have the output of dustjs-helper be dust with helpers then we would in addtion add
|
Up for debate:
vs.
vs.
|
I prefer the last option, it would mean that I only need to include the helpers instead of including core + helpers. |
Returning In all of these cases dust object in require cache will be altered. That's most likely how helpers code will be used. I guess return value does not matter much. I don't mind dustjs-helpers module returning |
Agreed it's not worth the back-incompat change. This should be a pretty quick change to move I believe we should still recommend folks use the more verbose
With this, developers will have full control of which |
+1 I think we should be more explicit when requiring core dust and dust helpers. How can we recommend this approach? Should this be added to README.md? I'll update #73 to include |
…dInAttic#64 'Use iteration to populate dust.helpers'
Would it be possible to do both? If the dust object exists, simply extend it and return the extended dust object. Or if I simply require the helpers then it requires the defined package version and returns it a new dust object. This would be backwards compatible, allowing for someone to include whichever version of dust, or allow for a single package include. Basically just moving the dust object to the front of the check vs always requiring on the server.
|
I think the current proposal will do both. With the subtle differences that |
I've just run into this problem, and my temporary fix is to clobber
So line one loads dustjs-linkedin from my project's node_modules, then line two adds helpers to its private version of dustjs-linkedin. I don't see anyother way to make that use case work beside removing the dependency from your package.json. Is that not a deal killer for this use case? I don't mind keeping the versions in sync on my own, but I can't imagine that this is tenable from the project's perspective. |
After a little more thought.... Looking at dustmotes-provide, for instance. If I Is best practice something like:
But what now for third party stuff? For a single method like
This is backward compatible and intuitive so long as nobody has named their helper "merge". |
+1 for the dust.helpers.merge solution. |
Passing along another disgruntled user. psteeleidem [9:10 AM] psteeleidem [9:10 AM] psteeleidem [9:11 AM] |
+1 dust.helpers.eq = function(chunk, context, bodies, params) { ... };
dust.helpers.ne = function(chunk, context, bodies, params) { ... };
// ... Am I missing something? |
…g dust.helpers
Please accept the following Pull Request or let me know if any other changes need to be made: Thanks, |
A huge +1 on this. It cost me an hour last night tracing down just why dust.helpers was getting clobbered. It turns out that dust helpers loaded dustjs-linked in as a dependency in node and that copy was nuking the already defined helpers. Patrick's change should be totally safe as all he did was assign each helper directly to dust.helpers rather than to helpers and then assign dust.helpers=helpers; at the end thus clobbering any earlier user-defined helpers. Can we at least get this done? Just saw another victim on stack exchange: http://stackoverflow.com/questions/24418171/using-dustjs-helpers-with-kraken-js. I think this manifests in some other issues over in dustjs-linked in also. |
With version 1.2 requiring helpers on the server side adds no helpers to the dust object. It does work fine on the client side.
This outputs {} when used on the server side only. 1.1.x will output the helpers in the object.
The text was updated successfully, but these errors were encountered: