-
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
Allow dust.helpers.tap on dust body functions #71
Conversation
//if this function is dust body function, it will be rendered here with chunk.render call | ||
//render result will be saved into output variable; render will return chunk object in this case | ||
//if input is a simple function (not a dust body function) it will be invoked by chunk.render call; | ||
//result of simple function execution will be returned and saved to out variable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you simplify the above comment since the chunk.render call is made regardless.
Updated comments and added additional unit test |
|
||
//assume it's a simple function call when return result is not a chunk | ||
//and re-assign out to output so it can be returned as final result | ||
if(typeof out.untap === 'undefined') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!(out instanceOf Chunk) would be more explicit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice! I was looking for a way to do this. Will update the code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't use Chunk here :(
Sine helpers are in a different closure from dust core Chunk is not available here.
Is there any better way to do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if you did this:
if(Object.getPrototypeOf(out) !== Object.getPrototypeOf(chunk))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to MDN Object.getPrototypeOf
is not supported by IE8 and earlier. Is this something we need to worry about?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about out.constructor !== chunk.constructor
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That works better
sweet! this seems like a pretty complete solution. some side effects:
|
} | ||
|
||
var dustBodyOutput = '', | ||
simpleFunctionOutput; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about the name returnValue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
returnValue
instead of dustBodyOutput
or simpleFunctionOutput
? I wanted to make names a bit more self explanatory. output
and out
I used initially seemed confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for simplefFunctionOutput
. i think dustBodyOutput
is nice as is.
definitely agree this is confusing. i think returnValue implies it's coming from a function...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like returnValue
too, I think this name works well here. Updated to use returnValue
instead of simpleFunctionOutput
.
lgtm, Can you look at it once more and pull @jimmyhchan |
dustjs-linkedin#423 fix dust.helpers.tap to work with dust body functions. Fix tap helper to not rely on isFunction flag set in dust core. Using helper.tap on Context functions (function in your JSON context) will now get chunk and context as arguments.
Calling dust.helpers.tap on dust body functions does not work because of linkedin/dustjs#423
This changes implementation of tap helper not to rely on isFunction flag set in dust core.