Skip to content

Latest commit

 

History

History
81 lines (62 loc) · 1.46 KB

README.md

File metadata and controls

81 lines (62 loc) · 1.46 KB

event-emitter-tree

event emitter of tree shape, offer pipe operation.

Feature

  • event of tree shape
  • trigger eventItem and trigger eventTree
  • pipe operation
  • support typescript

Doc

Install

  yarn add event-emitter-tree
  npm i event-emitter-tree

Use

  • use with esm
  import {EventCore} from 'event-emitter-tree';
  • use with commonjs
  const {EventCore} = require('event-emitter-tree');

Description

  • the tree forked by a string ->
  • take pe for an example, if you bind event pe,pe->basketball, pe->basketball->shooting, pe->football->defence, then you can trigger one of them or a tree flexibly.
  • bind Event:
  let core = new EventCore();
  core.on('pe', fnPe);
  core.on('pe->basketball', fnPeBasketball);
  core.on('pe->basketball->shooting', fnPeBasketballShooting);
  core.on('pe->football->defence', fnPeFootballDefence);
  • the eventTree would be as follows:
{
  pipe: pipePe,
  tree: {
    basketball: {
      pipe: pipePeBasketball,
      tree: {
        shooting: {
          pipe: pipePeBasketballShooting
        }
      }
    },
    football: {
      tree: {
        defence: {
          pipe: pipePeFootballDefence
        }
      }
    }
  }
}
  • you can trigger eventItem or eventTree
  core.trigger('pe->basketball');
  core.triggerTree('pe')