Skip to content

Commit

Permalink
Merge pull request #130 from canjs/old-value
Browse files Browse the repository at this point in the history
Pass down previous value to onValue callback
  • Loading branch information
m-mujica committed Feb 28, 2018
2 parents 7530347 + 61b5e8c commit 5a66006
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions proto-compute.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,8 @@ canReflect.assignSymbols(Compute.prototype, {
"can.getValue": Compute.prototype.get,
"can.valueHasDependencies": hasDependencies,
"can.onValue": function onValue(handler, queue) {
function translationHandler(ev, newValue) {
handler(newValue);
function translationHandler(ev, newValue, oldValue) {
handler(newValue, oldValue);
}
singleReference.set(handler, this, translationHandler);
//!steal-remove-start
Expand Down
14 changes: 13 additions & 1 deletion proto-compute_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,6 @@ QUnit.test("can-reflect setValue", function(){
QUnit.equal(a.get(), "A", "compute");
});


QUnit.test("registered symbols", function() {
var a = new Compute("a");

Expand All @@ -430,3 +429,16 @@ QUnit.test("registered symbols", function() {
a[canSymbol.for("can.offValue")](handler);
a.set("d"); // doesn't trigger handler
});

QUnit.test("canReflect.onValue should get the previous value", function(assert) {
var a = new Compute("a");
var done = assert.async();

canReflect.onValue(a, function(newVal, oldVal) {
assert.equal(newVal, "b");
assert.equal(oldVal, "a");
done();
});

a.set("b");
});

0 comments on commit 5a66006

Please sign in to comment.