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

implement equals method for equivalent ContextClosure objects #20

Merged
merged 5 commits into from
Aug 8, 2018

Conversation

nateps
Copy link
Contributor

@nateps nateps commented Aug 4, 2018

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) with ContextClosure#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 its ignoreTemplate field if the field is a ContextClosure, as DepedencyOptions.shouldIgnoreTemplate(template, options) will always get a template generated by derby-parsing, which means it will never get a ContextClosure.

@nateps nateps requested a review from ericyhwang August 4, 2018 01:35
nateps added 2 commits August 6, 2018 22:12
… 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.
@ericyhwang
Copy link
Contributor

BTW, I edited the PR description to refer to the Saddle PR - I like cross-linking. I also added some description for the new ignoreTemplate unwrapping commits.

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) &&
Copy link
Contributor

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?

Copy link
Contributor Author

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

@nateps nateps merged commit 5d19968 into master Aug 8, 2018
@nateps nateps deleted the context-closure-equals branch August 8, 2018 20:13
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.

2 participants