Skip to content
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

Don't instaevaluate generated body_ functions. #513

Merged
merged 1 commit into from
Nov 4, 2014

Conversation

sethkinast
Copy link
Contributor

Instead, place them into the context and attempt to render their containing block.

Closes #512.

@@ -181,7 +181,7 @@

for (i=0, len=bodies.length; i<len; i++) {
out[i] = 'function body_' + i + '(chk,ctx){' +
blx + 'return chk' + bodies[i] + ';}';
blx + 'return chk' + bodies[i] + ';}body_' + i + '.internal=true;';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we use to (pre 2.4) have an isFunction check... perhaps it never worked as intended.... Anyways, this is much nicer since it's on the compiled object and not in the run time ctx object.

Now that we're in compile time, is it possible (perhaps overkill, might make it slower) to make body functions smarter. Instead of named functions can these be instances of a Bodies class. I was never a fan of how block was implemented, the strange relationship with elem and never liked the fragile calls to body(chk,ctx). This is a pretty big change but some benefits: the implementation stays in dust and not in the compiler (DRYer no need to repeat .internal), more extensible if we need to add additional properties, calls to body will be replace with body.render() which will always to defined , potentially allows some cleanup to distinguish elem, block, body_0 etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment makes sense, I think we should open an feature issue on it. I can see how it could make things a lot less fragile, especially because I'm basically poor-man's-classing these functions already.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

@jimmyhchan
Copy link
Contributor

see comment above but 👍 since this address the issue cleanly

@@ -181,7 +181,7 @@

for (i=0, len=bodies.length; i<len; i++) {
out[i] = 'function body_' + i + '(chk,ctx){' +
blx + 'return chk' + bodies[i] + ';}';
blx + 'return chk' + bodies[i] + ';}body_' + i + '.__dust=!0;';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make this .__dustBody

…to the context and attempt to render their containing block.

Closes linkedin#512.
prashn64 added a commit that referenced this pull request Nov 4, 2014
Treat compiled body functions as blocks to render instead of functions to evaluate.   Dust body functions are now flagged with .___dustBody to differentiate them from functions set in the context.
@prashn64 prashn64 merged commit 3c684b3 into linkedin:master Nov 4, 2014
@sethkinast sethkinast deleted the no-eval-bodies branch November 4, 2014 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sections pointing to functions should act like normal sections
3 participants