Neatly Packaged Modules

    greenbus

    1.0.1 • Public • Published

    greenbus is a simple lib for listenning and dispatching customized event, only 2kb !

    Install

    Browser

    <script src='path/to/greenbus.min.js'></script>
    <script>
        var bus = new Bus()
    </script>

    CommonJS && Node.js

    npm install greenbus --save

    AMD && Require.js

    define(['path/to/greenbus.js'], function(Bus) {...});

    Instance Methods

    on(eventName, callbackOrCallbacks, [context], [onlyOnce])

    • Arguments:
      • eventName: {string}
      • callbackOrcallbacks: {function | array}
      • context: {object} the context bind to callback
      • onlyOnce: {boolean} whether to be triggered only once

    once(eventName, callbackOrCallbacks, [context])

    • description: same as on while callbacks would only being triggered once

    emit(eventName, [overload])

    • description: emit an event and pass the overload to callbacks as the only argument

    off([eventName], [callbackOrCallbacks])

    • description: if no arguments provided, remove all events and callbacks. if only eventName provided, remove all callbacks attached to the event. if both eventName and callbackOrcallbacks provided, remove the callback or callbacks on the event.

    Keywords

    Install

    npm i greenbus

    DownloadsWeekly Downloads

    3

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    10.9 kB

    Total Files

    7

    Last publish

    Collaborators

    • jasonzoujkl