Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

custom-event-js

shystruk159MIT1.1.1

Custom Event Dispatcher

Custom Event, custom-event, events, dispatcher, event dispatcher, event bus

readme

Custom Event Dispatcher Twitter URL

MIT Licence npm version Known Vulnerabilities

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 find here.

Custom Event Dispatcher works in all popular browsers

Install

npm

npm install --save custom-event-js

yarn

yarn add custom-event-js --save

Example

import CustomEvent from 'custom-event-js'

// Listen event 'SHOW_NAME'
CustomEvent.on('SHOW_NAME', (data) => {
    console.log(data.detail) // { name: 'GitHub' }
})

// Dispatch event 'SHOW_NAME' with data
CustomEvent.dispatch('SHOW_NAME', { name: 'GitHub' })

// Remove event listener
CustomEvent.off('SHOW_NAME')

// Remove a specific callback from event listener
CustomEvent.off('SHOW_NAME', callback)

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 all event listeners for the event

  • off(eventName, callback) remove a specific event listener for the event

Contributing

Any contributions you make are greatly appreciated.

Please read the Contributions Guidelines before submitting a PR.

License

MIT © Vasyl Stokolosa