fix emboxValue

This commit is contained in:
David Greenspan
2013-12-10 19:50:11 -08:00
parent 0f26061cc4
commit b4cd5ec4bd
2 changed files with 15 additions and 4 deletions

View File

@@ -690,6 +690,18 @@ var codeGenInclusionArgs = function (tag) {
return [];
};
// Returns true if `a` and `b` are `===`, unless they are of a mutable type.
// (Because then, they may be equal references to an object that was mutated,
// and we'll never know. We save only a reference to the old object; we don't
// do any deep-copying or diffing.)
var safeEquals = function (a, b) {
if (a !== b)
return false;
else
return ((!a) || (typeof a === 'number') || (typeof a === 'boolean') ||
(typeof a === 'string'));
};
Spacebars.include = function (kindOrFunc, args) {
args = args || {};
if (typeof kindOrFunc === 'function') {
@@ -740,7 +752,7 @@ Spacebars.include = function (kindOrFunc, args) {
if (k === '__content' || k === '__elseContent')
emboxedArgs[k] = args[k];
else
emboxedArgs[k] = UI.emboxValue(args[k]);
emboxedArgs[k] = UI.emboxValue(args[k], safeEquals);
}
return kind.extend(emboxedArgs);

View File

@@ -110,9 +110,8 @@ UI.emboxValue = function (funcOrValue, equals) {
var oldResult = curResult;
curResult = func();
if (! c.firstRun) {
// XXX THE `===` CHECK BREAKS TEST-IN-BROWSER
// if (! (equals ? equals(curResult, oldResult) :
// curResult === oldResult))
if (! (equals ? equals(curResult, oldResult) :
curResult === oldResult))
resultDep.changed();
}
});