1.0.1 • Published 6 years ago

greenbus v1.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

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.