Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Fix ObserverTransform.getValue/setValue/discardChanges
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rafaelw committed Dec 16, 2013
1 parent bf861dd commit d5e8dc3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
13 changes: 6 additions & 7 deletions src/observe.js
Original file line number Diff line number Diff line change
Expand Up @@ -922,23 +922,22 @@
},

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() {
return this.observable_.deliver();
},

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() {
Expand Down
8 changes: 6 additions & 2 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down

0 comments on commit d5e8dc3

Please sign in to comment.