From d5e8dc35d0c7886e849a848b3a3f5d30b25a682c Mon Sep 17 00:00:00 2001 From: Rafael Weinstein Date: Mon, 16 Dec 2013 13:27:58 -0800 Subject: [PATCH] Fix ObserverTransform.getValue/setValue/discardChanges ObserverTransform needs to conform to the contract of Observable: -getValue/setValue do not affect the last reported value (synchronously retrieve or set the underlying value) -discardChanges sets the last reported value to the current value R=arv BUG= Review URL: https://codereview.appspot.com/41260044 --- src/observe.js | 13 ++++++------- tests/test.js | 8 ++++++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/observe.js b/src/observe.js index c555570..68c124f 100644 --- a/src/observe.js +++ b/src/observe.js @@ -922,11 +922,12 @@ }, getValue: function() { - return this.observable_.getValue(); + return this.getValueFn_(this.observable_.getValue()); }, discardChanges: function() { - return this.getValueFn_(this.observable_.discardChanges()); + this.value_ = this.getValueFn_(this.observable_.discardChanges()); + return this.value_; }, deliver: function() { @@ -934,11 +935,9 @@ }, setValue: function(value) { - this.value_ = this.setValueFn_(value); - if (this.dontPassThroughSet_ || !this.observable_.setValue) - return; - - return this.observable_.setValue(this.value_); + value = this.setValueFn_(value); + if (!this.dontPassThroughSet_ && this.observable_.setValue) + return this.observable_.setValue(value); }, close: function() { diff --git a/tests/test.js b/tests/test.js index b5d2e86..b96d9f3 100644 --- a/tests/test.js +++ b/tests/test.js @@ -333,8 +333,12 @@ suite('ObserverTransform', function() { observer.setValue(2); assert.strictEqual(obj.foo, 1); - assert.strictEqual(2, observer.discardChanges()); - assertNoChanges(); + assert.strictEqual(2, observer.getValue()); + assertPathChanges(2, 4); + + obj.foo = 10; + assert.strictEqual(20, observer.getValue()); + assertPathChanges(20, 2); observer.close(); });