Skip to content

Commit

Permalink
lifecylle) Expand LifeCycle::anchorTo to latch onto other `LifeCycl…
Browse files Browse the repository at this point in the history
…e`-likes
  • Loading branch information
brianmhunt committed Nov 6, 2019
1 parent e86bb47 commit 90f1223
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/lifecycle/src/LifeCycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,13 @@ export default class LifeCycle {
this.addDisposable({ dispose })
}

anchorTo (node) {
addDisposeCallback(node, () => this.dispose())
this[ANCHOR_NODE] = node
anchorTo (nodeOrLifeCycle) {
if ('addDisposable' in nodeOrLifeCycle) {
nodeOrLifeCycle.addDisposable.push(this)
} else {
this[ANCHOR_NODE] = nodeOrLifeCycle
addDisposeCallback(nodeOrLifeCycle, () => this[ANCHOR_NODE] === nodeOrLifeCycle && this.dispose())
}
}

dispose () {
Expand Down

0 comments on commit 90f1223

Please sign in to comment.