Custom Event Dispatcher
The Custom Event Dispatcher provides the ability to communicate inside your application by dispatching events and listening to them. It also runs polyfill for Internet Explorer 9 and higher. What is the CustomEvent interface you may find here.
Install
npm
npm install --save custom-event-js
yarn
yarn add custom-event-js --save
Example
import CustomEvent from 'custom-event-js'
CustomEvent.ON('SHOW_NAME', (detail) => {
console.log(detail)
})
CustomEvent.DISPATCH('SHOW_NAME', { name: 'GitHub' })
CustomEvent.OFF('SHOW_NAME')
API
-
ON(eventName, callback) add an appropriate event listener. When event gets fired callback will be called with detail argument
-
DISPATCH(eventName, detail) dispatch event to all event listeners
-
OFF(eventName) remove event listener
Contributing
Any contributions you make are greatly appreciated.
Please read the Contributions Guidelines before submitting a PR.
License
MIT © Vasyl Stokolosa