github.com/developit/mitt
- Folder:src
- Folder:test
- File:.gitignore
- File:.travis.yml
- File:README.md
- File:package.json
- File:rollup.config.js
README.md
mitt
Tiny (~200b) functional event emitter / pubsub.
It's tiny: no dependencies and only 190 bytes when gzipped (250b without).
Installation
npm install --save mitt
API
mitt
Mitt: Tiny (~200b) functional event emitter / pubsub.
Returns Mitt
on
Register an event handler for the given type.
Parameters
typeString Type of event to listen for, or"*"for all eventshandlerFunction Function to call in response to the given event
off
Remove an event handler for the given type.
Parameters
typeString Type of event to unregisterhandlerfrom, or"*"handlerFunction Handler function to remove
emit
Invoke all handlers for the given type.
If present, "*" handlers are invoked prior to type-matched handlers.
Parameters
typeString The event type to invokeevent[Any] An event object, passed to each handler
Sample usage
import mitt from 'mitt'
let emitter = mitt()
// listen to an event
emitter.on('foo', e => console.log('foo', e) )
// listen to all events
emitter.on('*', (type, e) => console.log(type, e) )
// fire an event
emitter.emit('foo', { a: 'b' })