Skip to content

6.0 build target with comment nodes #701

@justinbmeyer

Description

@justinbmeyer

To make building templates faster, make sure to render with comment nodes.

Currently, can-stache creates placeholder text nodes for anything "live" using can-view-target.

presentation

For stache like start{{#if(foo)}}BAR{{/if}}end instead of placeholder textNodes, create two comment nodes. Resulting DOM would look like:

start<!-- Observe<if(foo)> -->BAR<!-- Observe<if(foo)> -->end

Before:

hydrate([
  "start",
  function(){ this //-> text node 
  },
  "end"
])
hydrate([
  "start",
  {comment: "{{ if(foo) }}", callbacks: [ function(){} ]},
  {comment: "{{ /if }}"
  "end"
])

can-view-target has already been changed to "force" comments instead of textNodes:

https://github.com/canjs/can-view-live/blob/d541c95d04d6db7f6ec2988bc319c98c049328ea/lib/helpers.js#L63

If you have something like {{foo}} ... this should create a placecholder textNode, however, there are times where you can opt out of this, like safeString or components, with those, we'd need to "force" into comment nodes.

Approach

  1. Create a performance test
  2. Make can-view-live warn if it's forcing a "comment node". You will see a LOT of warnings with can-view-target, ignore those.
  3. Make those warnings going away in can-stache.
  4. Remove the warnings?

Code you might want to change

instead of just adding a function, add two comment nodes:

this.last().add(newSection.targetCallback);

should we be forcing comment nodes here:

section.add(mustacheCore.makeLiveBindingPartialRenderer(stache, copyState({ filename: section.filename, lineNo: lineNo })));

... or in the .add() function?

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions