Skip to content

stagas/tree-emit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tree-emit

emit events to every listener in object tree

Install

$ component install stagas/tree-emit

Usage

var emit = require('tree-emit');

function print(s) {
  document.write(s);
}

var obj = {
  onfoo: print,
  some: {
    notonfoo: print,
    level: {
      other: 'ignored',
      deep: {
        onfoo: print
      }
    }
  }
};

emit(obj, 'foo', 'bar'); // => barbar

API

emit(target, name, [...])

Emit name event to target passing following parameters.

emit.depth(target, name, [...])

Emit depth-first as method.

emit.breadth(target, name, [...])

Emit breadth-first.

emit.filter(fn)

Filter traversal using fn.

The passed function is invoked with (key, property) and must return true or false depending on whether to traverse down that property.

emit.intercept(emitter, out)

Intercept an emitter and tree-emit its events to out.

emit.wrap(emitter)

Wrap emitter to tree-emit on itself.

See also

stagas/traverse-object

License

MIT

About

emit events to every listener in object tree

Resources

Stars

Watchers

Forks

Packages

No packages published