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

Remove NodeLists from Stache #1048

Merged
merged 13 commits into from
Jun 10, 2014
Merged

Remove NodeLists from Stache #1048

merged 13 commits into from
Jun 10, 2014

Conversation

justinbmeyer
Copy link
Contributor

This not-working pull request begins the ability to remove nodeLists from can.stache. When fully implemented, this will dramatically improve live-binding performance in IE8.

Short story

It is impossible in IE8 and lower to set expando properties on textNodes. For example, the following does not work:

var tn = document.createTextNode("foo");
tn.expandoProperty =  5;

can/view/node_list maintains a map of element IDs to the live-binding nodeList that is keeping those elements live.

It is impossible to give an ID to a textNode so we must use an array instead. This changes a critical path in live-binding from O(1) to O(n) where n is the number of textNodes being live bound.

Long story

For templates like:

{{#if foo}}FOO{{#if bar}}B<b>a</b>R{{/if}}.{{/if}}

It is important for the {{#if foo}} to know about all the elements it needs to remove. can/view/nodeLists helps us setup a structure that looks like:

[
  "FOO",
  ["B",<b/>,"R"],
  "." 
]

where text nodes are represented by "quotes" and normal elements by <angles>.

This array of arrays structure is used to remove elements if {{#if foo}} was to become false.

The fix

This branch includes a SectionNode construct which can represent {{#if foo}}. Child sections will have access to the parent SectionNodes.

When a live-bound element is found, it should check its parent SectionNode for the same element and replace the parent SectionNode's array's element with a pointer to the child SectionNode in a similar way that happens with NodeLists.

This will be MUCH faster for IE8 as it will only have to find the textNode that is being replaced within its parent Section's nodes.

@justinbmeyer
Copy link
Contributor Author

The latest commit passes all stache tests. It doesn't completely avoid needing expandos on textNodes but instead of comparing against all live textNodes in the page, it compares a much much smaller set of textNodes.

@daffl daffl added this to the 2.1.2 milestone Jun 4, 2014
daffl added a commit that referenced this pull request Jun 10, 2014
Remove NodeLists from Stache
@daffl daffl merged commit 5cf7469 into master Jun 10, 2014
@daffl daffl deleted the no-nodeList branch June 10, 2014 20:36
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.

None yet

2 participants