emitry

    1.3.0 • Public • Published

    Travis npm npm codecov.io

    emitry

    simple event emitter.

    Why emitry?

    • Small - The source code is less than 100 lines. After minified and gzipped, only 450B.
    • Simple - Only 4 api, but it can solve most of the scenes.
    • Cross platform - It can work on nodejs, browser...

    Install

    npm i emitry

    or

    <script src="/path/emitry.umd.min.js"></script>
    var emitry = new Emitry();

    Usage

    import Emitry from 'emitry';
    const emitry = new Emitry();

    Api

    on(name, (value1, value2, ...) => {})

    Subscribe to an event.

    emitry.on('oh', (value1, value2) => {
      console.log(value1, value2);
    });

    once(name, value1, value2, ...)

    Subscribe to an event. Only trigger once, after triggered will remove from events list.

    emitry.once('oh', (value1, value2) => {
      console.log(value1, value2);
    });

    emit(name, value1, value2, ...)

    Emit an event.

    emitry.emit('oh', 'my god', 'my dear');  // 'mygod' 'my dear

    off(name, callback)

    Remove a listener from the listener array for the specified event.

    emitry.off('oh', (value1, value2) => {
      console.log(value1, value2);
    });

    off([names])

    Remove specify events by a list of names.

    emitry.off(['a', 'b']);

    off()

    Remove all events.

    emitry.off();

    Install

    npm i emitry

    DownloadsWeekly Downloads

    9

    Version

    1.3.0

    License

    MIT

    Unpacked Size

    12.9 kB

    Total Files

    10

    Last publish

    Collaborators

    • pjy