Skip to content

Commit

Permalink
fix issue with overidability of computed.volatile
Browse files Browse the repository at this point in the history
  • Loading branch information
bekzod committed Jan 5, 2019
1 parent 0c212ee commit 21728e3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
11 changes: 5 additions & 6 deletions packages/@ember/-internals/metal/lib/computed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,12 +501,11 @@ class ComputedProperty extends Descriptor implements DescriptorWithDependentKeys

/* called before property is overridden */
teardown(obj: object, keyName: string, meta?: any): void {
if (this._volatile) {
return;
}
let cache = peekCacheFor(obj);
if (cache !== undefined && cache.delete(keyName)) {
removeDependentKeys(this, obj, keyName, meta);
if (!this._volatile) {
let cache = peekCacheFor(obj);
if (cache !== undefined && cache.delete(keyName)) {
removeDependentKeys(this, obj, keyName, meta);
}
}
super.teardown(obj, keyName, meta);
}
Expand Down
14 changes: 14 additions & 0 deletions packages/@ember/-internals/metal/tests/computed_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,20 @@ moduleFor(
assert.equal(count, 1, 'should have invoked computed property');
}

['@test can override volatile computed property'](assert) {
let obj = {};

defineProperty(
obj,
'foo',
computed(function() {}).volatile()
);

set(obj, 'foo', 'boom');

assert.equal(obj.foo, 'boom');
}

['@test defining computed property should invoke property on set'](assert) {
let obj = {};
let count = 0;
Expand Down

0 comments on commit 21728e3

Please sign in to comment.