Skip to content

Commit

Permalink
issues #22: Add protection in Arch.link() to not call plan.link() whe…
Browse files Browse the repository at this point in the history
…n link in Arch was already exist
  • Loading branch information
afelix committed Apr 12, 2012
1 parent 2190b17 commit dcde819
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/arch.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,16 @@ module.exports = INHERIT({

for (var i = 0; i < parents.length; i++) {
parent = parents[i];
children = this.children[parent] || (this.children[parent] = []);
if (!this.hasParents(child, parent)) {
children = this.children[parent] || (this.children[parent] = []);

if (_parents.indexOf(parent) === -1) _parents.push(parent);
if (children.indexOf(child) === -1) children.push(child);
if (_parents.indexOf(parent) === -1) _parents.push(parent);
if (children.indexOf(child) === -1) children.push(child);

for (var k in this.plans) {
var p = this.plans[k];
if (p.hasNode(child) || p.hasNode(parent)) p.link(child, parent);
for (var k in this.plans) {
var p = this.plans[k];
if (p.hasNode(child) || p.hasNode(parent)) p.link(child, parent);
}
}
}
},
Expand Down
2 changes: 2 additions & 0 deletions test/arch-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ suite
arch.setNode('A', { run: 'testA' });
arch.setNode('B', { run: 'testA' });
arch.link('B', 'A');
arch.link('B', 'A');

return arch;
},
Expand All @@ -162,6 +163,7 @@ suite
arch.setNode('A', { run: 'testA' });
arch.setNode('B', { run: 'testB' }, 'A');
arch.unlink('B', 'A');
arch.unlink('B', 'A');

return arch;
},
Expand Down

0 comments on commit dcde819

Please sign in to comment.