-
Notifications
You must be signed in to change notification settings - Fork 15
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
implement equals method for equivalent ContextClosure objects #20
Conversation
… source template The desire of ignoreTemplate is to prevent over-computing bindings for templates. However, wrapping templates in ContextClosures was preventing us from detecting the template that should be ignored. This resolves the issue by ignoring the base template of the ContextClosure
… and not wrapped already It could be possible for an object to have an unwrapped Template in it that is returned by looking up segemtns, so this shouldn't be an else. Also, wrapping a template in two ContextClosures isn't needed, since the inner ContextClosure is going to be the only one that has an effect. Thus, do check for an existing ContextClosure to avoid direct double wrapping.
BTW, I edited the PR description to refer to the Saddle PR - I like cross-linking. I also added some description for the new |
lib/templates.js
Outdated
var closureContext = context.closureChild(this.context); | ||
return this.template.dependencies(closureContext, options); | ||
}; | ||
ContextClosure.prototype.equals = function(other) { | ||
return (other instanceof ContextClosure) && | ||
(other.template === this.template) && |
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.
Do we need to worry about this.template
or other.template
themselves being ContextClosures?
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.
Good idea. Let's recursively use the equals function
Resolve issue with determining if the same template is being rendered and binding should not update (because the template has not changed). This issue was created because the template was wrapped in a new ContextClosure object.
Solution is to override the base
Template#equals
method (added in derbyjs/saddle#27) withContextClosure#equals
, which treats ContextClosures as equal if they have the same template and context properties - meaning they would render identical output in all cases. This fixes issues with over-rendering.This also has
DependencyOptions
fully unwrap itsignoreTemplate
field if the field is a ContextClosure, asDepedencyOptions.shouldIgnoreTemplate(template, options)
will always get atemplate
generated by derby-parsing, which means it will never get a ContextClosure.