chirashi-event-emitter
v2.0.3
Published
Simplest event emitter
Downloads
2
Maintainers
Readme
Intro
This is a tiny factory fonction to create a really simple event emitter.
Get started
Find API documentation on chirashijs.github.io/chirashi-event-emitter.
Quick view
Installation
Using npm / yarn (recommended)
yarn add chirashi-event-emitter
or
npm i --save chirashi-event-emitter
Now you can import methods in your project:
import EventEmitter from 'chirashi-event-emitter'
const emitter = EventEmitter()
const off = emitter.on('event', (foo, bar) => {
console.log(foo, bar)
})
emitter.emit('event', 'foo', 'bar')
// logs: foo, bar
off()
emitter.emit('event', 'foo', 'bar')
// won't log anything
Standalone
You can download chirashi-event-emitter.js or chirashi-event-emitter.min.js and load it using a script tag. You can also use CDN version of those files from unpkg using the link https://unpkg.com/chirashi@latest/dist/chirashi-event-emitter.min.js. It'll create an instance of ChirashiEventEmitter on your window. Then use as following example
const emitter = ChirashiEventEmitter()
const off = emitter.on('event', (foo, bar) => {
console.log(foo, bar)
})
emitter.emit('event', 'foo', 'bar')
// logs: foo, bar
off()
emitter.emit('event', 'foo', 'bar')
// won't log anything