Skip to content

Commit

Permalink
Merge pull request #1599 from bitovi/stache-plain-section
Browse files Browse the repository at this point in the history
makes section helper not bind on anything except that which should be bound
  • Loading branch information
daffl committed Apr 2, 2015
2 parents 3f169ec + 124f52e commit e8a6721
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
35 changes: 9 additions & 26 deletions view/stache/mustache_core.js
Expand Up @@ -338,39 +338,20 @@ steal("can/util",
}
} else if( mode === "#" || mode === "^" ) {
// Setup renderers.
var valueAndLength = new can.Compute(function(){
convertToScopes(helperOptions, scope, options, nodeList, truthyRenderer, falseyRenderer);
var evaluator = function(){
// Get the value
var value;
if (can.isFunction(name) && name.isComputed) {
value = name();
} else {
value = name;
}
var len,
arrayLike = utils.isArrayLike(value),
isObserveList;
if ( arrayLike ) {
isObserveList = utils.isObserveLike(value);
len = isObserveList ? value.attr("length") : value.length;
}
return {

value: value,
length: len,
isObserveList: isObserveList,
isArrayLike: arrayLike
};
});
convertToScopes(helperOptions, scope, options, nodeList, truthyRenderer, falseyRenderer);
return function(){
var data = valueAndLength.get();
// Get the value
var value = data.value;

// If it's an array, render.
if (data.isArrayLike ) {
var isObserveList = data.isObserveList;
if (utils.isArrayLike(value) ) {
var isObserveList = utils.isObserveLike(value);

if(data.length) {
if(isObserveList ? value.attr("length") : value.length) {
return (stringOnly ? getItemsStringContent: getItemsFragContent )
(value, isObserveList, helperOptions, options);
} else {
Expand All @@ -382,6 +363,8 @@ steal("can/util",
return value ? helperOptions.fn(value || scope, options) : helperOptions.inverse(scope, options);
}
};
evaluator.bindOnce = false;
return evaluator;
} else {
// not supported!
}
Expand Down Expand Up @@ -508,7 +491,7 @@ steal("can/util",
// parent expresions. If this value changes, the parent expressions should
// not re-evaluate. We prevent that by making sure this compute is ignored by
// everyone else.
var compute = can.compute(evaluator, null, false, true);
var compute = can.compute(evaluator, null, false, evaluator.bindOnce === false ? false : true);

// Bind on the compute to set the cached value. This helps performance
// so live binding can read a cached value instead of re-calculating.
Expand Down
21 changes: 21 additions & 0 deletions view/stache/stache_test.js
Expand Up @@ -3828,6 +3828,27 @@ steal("can/view/stache", "can/view","can/test","can/view/mustache/spec/specs","s

});

test("don't setup live binding for raw data with seciton helper", function () {
expect(0);
var template = can.stache("<ul>{{#animals}}" +
"<li></li>" +
"{{/animals}}</ul>");

var oldBind = can.bind;
can.bind = function(ev){
if(ev === "removed") {
ok(false, "listening to element removed b/c you are live binding");
}
oldBind.apply(this, arguments);
};

template({
animals: this.animals
});

can.bind = oldBind;
});

// the define test doesn't include the stache plugin and
// the stache test doesn't include define plugin, so have to put this here
test('#1590 #each with surrounding block and setter', function(){
Expand Down

0 comments on commit e8a6721

Please sign in to comment.