Skip to content

Commit

Permalink
Merge pull request #19178 from emberjs/bugfix/allow-cycles-in-compute…
Browse files Browse the repository at this point in the history
…d-deps
  • Loading branch information
rwjblue committed Oct 5, 2020
2 parents e2a6bab + b612d47 commit fb295a9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/@ember/-internals/metal/lib/computed.ts
Expand Up @@ -323,10 +323,6 @@ export class ComputedProperty extends ComputedDescriptor {
)
);

if (DEBUG) {
ALLOW_CYCLES!.set(tagFor(obj, keyName), true);
}

if (this._hasConfig === false) {
assert(
`Attempted to use @computed on ${keyName}, but it did not have a getter or a setter. You must either pass a get a function or getter/setter to @computed directly (e.g. \`@computed({ get() { ... } })\`) or apply @computed directly to a getter/setter`,
Expand Down Expand Up @@ -408,6 +404,10 @@ export class ComputedProperty extends ComputedDescriptor {

if (_dependentKeys !== undefined) {
updateTag(propertyTag!, getChainTagsForKeys(obj, _dependentKeys, tagMeta, meta));

if (DEBUG) {
ALLOW_CYCLES!.set(propertyTag, true);
}
}

meta.setValueFor(keyName, ret);
Expand Down Expand Up @@ -483,6 +483,10 @@ export class ComputedProperty extends ComputedDescriptor {

if (_dependentKeys !== undefined) {
updateTag(propertyTag, getChainTagsForKeys(obj, _dependentKeys, tagMeta, meta));

if (DEBUG) {
ALLOW_CYCLES!.set(propertyTag, true);
}
}

meta.setRevisionFor(keyName, valueForTag(propertyTag));
Expand Down
Expand Up @@ -6,6 +6,7 @@ import {
getWithDefault,
observer,
defineProperty,
notifyPropertyChange,
} from '@ember/-internals/metal';
import { oneWay as reads } from '@ember/object/computed';
import { A as EmberArray, isArray } from '../../..';
Expand Down Expand Up @@ -540,5 +541,28 @@ moduleFor(

assert.ok(true);
}

['@test computeds can have cycles'](assert) {
class CycleObject {
// eslint-disable-next-line getter-return
@computed('bar')
get foo() {}

// eslint-disable-next-line getter-return
@computed('foo')
get bar() {}
}

let obj = new CycleObject();

obj.bar;
obj.foo;

notifyPropertyChange(obj, 'bar');

obj.foo;

assert.ok(true);
}
}
);

0 comments on commit fb295a9

Please sign in to comment.