- Notifications
You must be signed in to change notification settings - Fork5
Event dispatcher based on the CustomEvent interface (works on browser)
License
shystruk/custom-event-js
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
The Custom Event Dispatcher provides the ability to communicate inside your application by dispatching events and listening to them. What is the CustomEvent interface you may findhere.
Custom Event Dispatcher works in all popular browsers
npm install --save custom-event-js
yarn add custom-event-js --save
importCustomEventfrom'custom-event-js'// Listen event 'SHOW_NAME'CustomEvent.on('SHOW_NAME',(data)=>{console.log(data.detail)// { name: 'GitHub' }})// Dispatch event 'SHOW_NAME' with dataCustomEvent.dispatch('SHOW_NAME',{name:'GitHub'})// Remove event listenerCustomEvent.off('SHOW_NAME')// Remove a specific callback from event listenerCustomEvent.off('SHOW_NAME',callback)
on(eventName, callback) add an appropriate event listener. When event gets fired callback will be called withdetail argument
dispatch(eventName, detail) dispatch event to all event listeners
off(eventName) remove all event listeners for the event
off(eventName, callback) remove a specific event listener for the event
Any contributions you makeare greatly appreciated.
Please read theContributions Guidelines before submitting a PR.
MIT ©Vasyl Stokolosa
About
Event dispatcher based on the CustomEvent interface (works on browser)