Skip to content

Commit

Permalink
Fix #1399
Browse files Browse the repository at this point in the history
Store - Cyclical Dependency Detected when child computed property defined before parent & grand-parent computed proprety
  • Loading branch information
btakita committed May 2, 2018
1 parent 6ec21f7 commit 4d8090a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
6 changes: 3 additions & 3 deletions store.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ assign(Store.prototype, {
var visited = blankObject();

function visit(key) {
if (visited[key]) return;

if (cycles[key]) {
throw new Error('Cyclical dependency detected');
}

if (visited[key]) return;
visited[key] = true;

var c = computed[key];

if (c) {
cycles[key] = true;
c.deps.forEach(visit);
sorted.push(c);
visited[key] = true;
}
}

Expand Down
22 changes: 22 additions & 0 deletions test/runtime/samples/store-computed-compute-graph/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Store } from '../../../../store.js';

const store = new Store();

export default {
store,

test(assert, component, target) {
store.compute('dep4', ['dep1', 'dep2', 'dep3'], (...args) => ['dep4'].concat(...args));
store.compute('dep1', ['source'], (...args) => ['dep1'].concat(...args));
store.compute('dep2', ['dep1'], (...args) => ['dep2'].concat(...args));
store.compute('dep3', ['dep1', 'dep2'], (...args) => ['dep3'].concat(...args));
store.set({source: 'source'});
assert.equal(JSON.stringify(store.get().dep4), JSON.stringify([
'dep4',
'dep1', 'source',
'dep2', 'dep1', 'source',
'dep3', 'dep1', 'source',
'dep2', 'dep1', 'source'
]));
}
};
Empty file.

0 comments on commit 4d8090a

Please sign in to comment.