From 61b5e8c0974e29cc4ee2386c456d2dd9af2137e1 Mon Sep 17 00:00:00 2001 From: Manuel Mujica Date: Tue, 27 Feb 2018 13:31:30 -0700 Subject: [PATCH] Pass down previous value to onValue callback Closes #129 --- proto-compute.js | 4 ++-- proto-compute_test.js | 14 +++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/proto-compute.js b/proto-compute.js index 96c690d..7ad3ba0 100644 --- a/proto-compute.js +++ b/proto-compute.js @@ -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 diff --git a/proto-compute_test.js b/proto-compute_test.js index 4b4747d..6de8efb 100644 --- a/proto-compute_test.js +++ b/proto-compute_test.js @@ -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"); @@ -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"); +});