TreeWalker in Bind & better variable names#7288
Merged
dreamofabear merged 6 commits intoampproject:masterfrom Feb 2, 2017
Merged
TreeWalker in Bind & better variable names#7288dreamofabear merged 6 commits intoampproject:masterfrom
dreamofabear merged 6 commits intoampproject:masterfrom
Conversation
jridgewell
requested changes
Feb 1, 2017
extensions/amp-bind/0.1/bind-impl.js
Outdated
| const elements = []; | ||
| let currentElement; | ||
| while (currentElement = treeWalker.nextNode()) { | ||
| elements.push(currentElement); |
Contributor
There was a problem hiding this comment.
So the great part about TreeWalker is you don't need to greedily grab every element into an array. Let's pass around the walker instance, and grab #nextNode in the chunktion loops.
c0a5605 to
7d844a5
Compare
jridgewell
reviewed
Feb 1, 2017
extensions/amp-bind/0.1/bind-impl.js
Outdated
| * @param {number} end | ||
| * @return {boolean} | ||
| */ | ||
| const scanFromTo = (start, end) => { |
Contributor
There was a problem hiding this comment.
So it looks like we could simplify this to take an element, boundElements, and bindings, and extract it out of the closure.
function scanElement(element, boundElements, bindings) {
// basically, the current scanElement_, with a bit of scanFromTo code
}
function chunktion(idleDeadline) {
let completed = false;
if (idleDeadline && !idleDeadline.didTimeout) {
while (idleDeadline.timeRemaining() > 1) {
var element = walker.next();
if (!element) {
completed = true;
break;
}
scanElement(element, boundElements, bindings);
}
} else {
for (let i = 0; i < 250; i++) {
var element = walker.next();
if (!element) {
completed = true;
break;
}
scanElement(element, boundElements, bindings);
}
}
}
Author
There was a problem hiding this comment.
Thanks for the suggestion. Simplified the helper method and extracted the loop.
I kept the advancement of the tree walker in the helper to avoid duplicating the conditional with break above. I also left it as a closure because modifying input params is bad for code readability.
c7f3438 to
9ad2368
Compare
jridgewell
approved these changes
Feb 2, 2017
torch2424
pushed a commit
to torch2424/amphtml
that referenced
this pull request
Feb 14, 2017
* rename 'bindings' to 'bound properties' * rename 'evaluatee' to 'binding' * use treewalker * minor tweak * justin's comments * simplify scan helper func
mrjoro
pushed a commit
to mrjoro/amphtml
that referenced
this pull request
Apr 28, 2017
* rename 'bindings' to 'bound properties' * rename 'evaluatee' to 'binding' * use treewalker * minor tweak * justin's comments * simplify scan helper func
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Partial for #7230, related to #6199.
getElementsByTagNamewithTreeWalkerfor DOM scanBindingDef->BoundPropertyDefandevaluatee->binding/to @jridgewell