-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
51e90fa
commit 0fd43ef
Showing
37 changed files
with
16,315 additions
and
9,927 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{yield (component "node" parent=this)}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import Component from '@glimmer/component'; | ||
|
||
export default class Node extends Component { | ||
children = new Set(); | ||
_didSetup = false; | ||
|
||
constructor() { | ||
super(...arguments); | ||
|
||
if (this.args.parent) { | ||
// register with parent | ||
this.args.parent.registerChild(this); | ||
} | ||
} | ||
|
||
willDestroy() { | ||
super.willDestroy(...arguments); | ||
|
||
if (this.args.parent) { | ||
this.args.parent.unregisterChild(this); | ||
} | ||
// this hook will be called depth-first from the top-level component | ||
// since we must destroy childs first, the first parent will | ||
// be responsible for destroying the children. `this._didSetup` guards | ||
// that we don't redestroy already destroyed children | ||
if (this._didSetup) { | ||
this.children.forEach(c => c.willDestroyNode()); | ||
this.teardown(); | ||
this._didSetup = false; | ||
} | ||
} | ||
|
||
/** | ||
* Method invoked by the child components to register themselves with their parent | ||
* @param {Component} child | ||
*/ | ||
registerChild(child) { | ||
this.children.add(child); | ||
|
||
if (this._didSetup) { | ||
child.setup(); | ||
} | ||
} | ||
|
||
/** | ||
* Method invoked by the child components to unregister themselves with their parent | ||
* @param {Component} child | ||
*/ | ||
unregisterChild(child) { | ||
this.children.delete(child); | ||
} | ||
|
||
/** | ||
* method responsible for setting up itself plus its children | ||
* it is called by the root initially and recursively to its children | ||
* @param {HTMLElement} element the root element | ||
*/ | ||
didInsertNode(element) { | ||
this.setup(element); | ||
|
||
this.children.forEach(c => c.didInsertNode(element)); | ||
} | ||
|
||
/** | ||
* method responsible for tearing down its children plus itself | ||
* it is called by the root initially and recursively to its children | ||
* @param {HTMLElement} element the root element | ||
*/ | ||
willDestroyNode(element) { | ||
this.children.forEach(c => c.willDestroyNode(element)); | ||
|
||
this.teardown(element); | ||
} | ||
|
||
/** | ||
* The actualy setup logic | ||
* @param {HTMLElement} element | ||
*/ | ||
setup(element) { | ||
// library setup code goes here | ||
if (typeof this.args.didInsertParent === 'function') { | ||
this.args.didInsertParent(element); | ||
} | ||
|
||
this._didSetup = true; | ||
} | ||
|
||
/** | ||
* The actualy teardown logic | ||
* @param {HTMLElement} element | ||
*/ | ||
teardown(element) { | ||
// library teardown code goes here | ||
if (typeof this.args.willDestroyParent === 'function') { | ||
this.args.willDestroyParent(element); | ||
} | ||
|
||
this._didSetup = false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<div | ||
{{did-insert (action this.didInsertNode)}} | ||
{{will-destroy (action this.willDestroyNode)}} | ||
...attributes | ||
> | ||
{{yield (component "node" parent=this)}} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import Node from './node'; | ||
|
||
export default class Root extends Node { | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.