events-tree
A tree structure for storing and accessing hierarchical event emitters
Install
$ npm install --save events-tree
Usage
var Tree = var tree = var node = tree node tree treebelow'foo.bar' { if path === 'foo.bar.baz' emitter }
API
Tree()
-> tree
Creates a new event tree.
tree.at(path)
-> eventEmitter
Access the EventEmitter at the given path. If no emitter is present, one will be created.
path
Type: string
Default: ''
A property path in dot syntax.
tree.root()
-> eventEmitter
Gets/creates the root emitter. Identical to tree.at()
.
tree.below([path], callback)
-> undefined
Traverse downwards through child nodes below the specified path.
path
Type: string
Default: ''
If a callback is passed as the first argument, traversal will begin at the root.
callback
Required
Type: function
Arguments: path, emitter
A callback to be called at each child node with the node path (relative to the root) and the emitter. Nodes without an emitter attached will be ignored.
var baz = treetreebelow'foo' { // only called once // path === 'foo.bar.baz' // emitter === baz}
tree.above(path, callback)
-> undefined
Traverse upwards through child nodes above the specified path.
path
Type: string
Default: ''
If no path is provided, above
is a noop.
callback
Required
Type: function
Arguments: path, emitter
A callback to be called at each child node with the node path (relative to the root) and the emitter. Nodes without an emitter attached will be ignored.
License
MIT © Ben Drucker