can.stache helpers that rely on array replacement don't work, but work in can.mustache #1652

Closed
imjoshdean opened this Issue Apr 29, 2015 · 1 comment

Comments

Projects
None yet
4 participants
@imjoshdean
Contributor

imjoshdean commented Apr 29, 2015

Found this issue earlier today. In a component, if you have a mustache helper that relies on running on a list's length changing, and you replace the list outside of the component - everything works just fine.

If you do this using Stache...the helper stops running.

Example (can.mustache): http://jsfiddle.net/imjoshdean/ojrhg955/
Example (can.stache): http://jsfiddle.net/imjoshdean/ojrhg955/1/

@akagomez

This comment has been minimized.

Show comment
Hide comment
@akagomez

akagomez Apr 29, 2015

Contributor

Essentially, a Stache helper's binding on a list will break if the list is overwritten.

// Helper
isListEmpty: function (options) {
  return ! this.attr('items.length') ? options.fn() : options.inverse(); 
}
// Template
{{#each items}}
  ...
{{/each}}
{{#isListEmpty}}
  There are no items!
{{/isListEmpty}}
scope.attr('items', new can.List([ ... ])); // Breaks helper binding
Contributor

akagomez commented Apr 29, 2015

Essentially, a Stache helper's binding on a list will break if the list is overwritten.

// Helper
isListEmpty: function (options) {
  return ! this.attr('items.length') ? options.fn() : options.inverse(); 
}
// Template
{{#each items}}
  ...
{{/each}}
{{#isListEmpty}}
  There are no items!
{{/isListEmpty}}
scope.attr('items', new can.List([ ... ])); // Breaks helper binding
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment