Remove NodeLists from Stache #1048

Merged
merged 13 commits into from Jun 10, 2014

Conversation

Projects
None yet
2 participants
@justinbmeyer
Contributor

justinbmeyer commented Jun 4, 2014

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

This comment has been minimized.

Show comment
Hide comment
@justinbmeyer

justinbmeyer Jun 4, 2014

Contributor

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.

Contributor

justinbmeyer commented Jun 4, 2014

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

@daffl daffl merged commit 5cf7469 into master Jun 10, 2014

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Details

@daffl daffl deleted the no-nodeList branch Jun 10, 2014

@justinbmeyer

This comment has been minimized.

Show comment
Hide comment
@justinbmeyer

justinbmeyer Jul 24, 2014

Contributor

This works because evaluator reads computes that will never change.

This works because evaluator reads computes that will never change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment