Skip to content

Commit

Permalink
Return last set compute value when it hasn't changed.
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl committed Mar 20, 2015
1 parent 930a8a9 commit cc3b70f
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 32 deletions.
8 changes: 4 additions & 4 deletions compute/compute_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -672,10 +672,10 @@ steal("can/compute", "can/test", "can/map", "steal-qunit", function () {
equal(curVal, 20);
break;
case 2:
equal(curVal, 30, "on bind");
equal(curVal, 20, "on bind");
break;
case 3:
equal(curVal, 40, "on bind");
equal(curVal, 30, "on bind");
break;
}
return curVal+add.get();
Expand All @@ -687,9 +687,9 @@ steal("can/compute", "can/test", "can/map", "steal-qunit", function () {

async.bind("change", function(){});

async.set(30);
async.set(20);

async.set(40);
async.set(30);
});


Expand Down
6 changes: 5 additions & 1 deletion compute/proto_compute.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,12 @@ steal('can/util', 'can/util/bind', 'can/util/batch', function (can, bind) {
this.lastSetValue = lastSetValue;
this._setUpdates = true;
this._set = function(newVal){
if(newVal === lastSetValue.get()) {
return this.value;
}

// this is the value passed to the fn
return lastSetValue.set(newVal);
lastSetValue.set(newVal);
};

// make sure get is called with the newVal, but not setter
Expand Down
46 changes: 25 additions & 21 deletions map/define/define_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -823,26 +823,30 @@ steal("can/map/define", "can/route", "can/test", "steal-qunit", function () {
equal(m.attr('computable'), 1, 'compute2 readable via .attr()');
});

test('value and get (#1521)', function(){
var MyMap = can.Map.extend({
define: {
list: {
value: function(){
return new can.List(['test']);
}
},
size: {
value: 1,
get: function(val){
var list = this.attr('list');
var length = list.attr('length');
return val + length;
}
}
}
});
// The old attributes plugin interferes severly with this test.
// TODO remove this condition when taking the plugins out of the main repository
if(!can.Map.attributes) {
test('value and get (#1521)', function () {
var MyMap = can.Map.extend({
define: {
data: {
value: function () {
return new can.List(['test']);
}
},
size: {
value: 1,
get: function (val) {
var list = this.attr('data');
var length = list.attr('length');
return val + length;
}
}
}
});

var map = new MyMap();
equal(map.attr('size'), 2);
});
var map = new MyMap({});
equal(map.attr('size'), 2);
});
}
});
2 changes: 1 addition & 1 deletion test/amd/dojo.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ <h2 id="qunit-userAgent"></h2>
"can/map/setter", "can/map/attributes",
"can/map/validations", "can/map/backup",
"can/map/list", "can/map/define",
"can/map/sort", "can/util/object",
"can/list/sort", "can/util/object",
"can/util/fixture", "can/view/bindings",
"can/view/live", "can/view/scope",
"can/util/string", "can/util/attr",
Expand Down
2 changes: 1 addition & 1 deletion test/amd/jquery-2.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ <h2 id="qunit-userAgent"></h2>
"can/map/setter", "can/map/attributes",
"can/map/validations", "can/map/backup",
"can/map/list", "can/map/define",
"can/map/sort", "can/control/plugin",
"can/list/sort", "can/control/plugin",
"can/view/modifiers", "can/util/object",
"can/util/fixture", "can/view/bindings",
"can/view/live", "can/view/scope",
Expand Down
2 changes: 1 addition & 1 deletion test/amd/jquery.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ <h2 id="qunit-userAgent"></h2>
"can/map/setter", "can/map/attributes",
"can/map/validations", "can/map/backup",
"can/map/list", "can/map/define",
"can/map/sort", "can/control/plugin",
"can/list/sort", "can/control/plugin",
"can/view/modifiers", "can/util/object",
"can/util/fixture", "can/view/bindings",
"can/view/live", "can/view/scope",
Expand Down
2 changes: 1 addition & 1 deletion test/amd/mootools.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ <h2 id="qunit-userAgent"></h2>
"can/map/setter", "can/map/attributes",
"can/map/validations", "can/map/backup",
"can/map/list", "can/map/define",
"can/map/sort", "can/util/object",
"can/list/sort", "can/util/object",
"can/util/fixture", "can/view/bindings",
"can/view/live", "can/view/scope",
"can/util/string", "can/util/attr",
Expand Down
2 changes: 1 addition & 1 deletion test/amd/yui.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ <h2 id="qunit-userAgent"></h2>
"can/map/setter", "can/map/attributes",
"can/map/validations", "can/map/backup",
"can/map/list", "can/map/define",
"can/map/sort", "can/util/object",
"can/list/sort", "can/util/object",
"can/util/fixture", "can/view/bindings",
"can/view/live", "can/view/scope",
"can/util/string", "can/util/attr",
Expand Down
2 changes: 1 addition & 1 deletion test/amd/zepto.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ <h2 id="qunit-userAgent"></h2>
"can/map/setter", "can/map/attributes",
"can/map/validations", "can/map/backup",
"can/map/list", "can/map/define",
"can/map/sort", "can/util/object",
"can/list/sort", "can/util/object",
"can/util/fixture", "can/view/bindings",
"can/view/live", "can/view/scope",
"can/util/string", "can/util/attr",
Expand Down

0 comments on commit cc3b70f

Please sign in to comment.