@emoji-gen/ptero
v0.3.0
Published
Simple CustomEvent listener and emitter
Downloads
3
Readme
ptero
:deciduous_tree: Simple CustomEvent listener and emitter
Getting started
$ npm install @emoji-gen/ptero --save # for npm users
$ yarn add @emoji-gen/ptero # for yarn users
import { Ptero } from '@emoji-gen/ptero'
const ptero = new Ptero()
ptero.on('eventname', e => {
console.log(e.detail) // => { foo: 1 }
})
ptero.emit('eventname', { foo: 1 })
References
new Ptero(target)
Create new Ptero
instance.
// Default target is `window`
const ptero = new Ptero()
// Set `document.body` for an event target
const ptero = new Ptero(document.body)
ptero.addListener(event, listener)
Listen a single custom event.
ptero.addListener('eventname', e => {
console.log(e.detail)
})
ptero.on(event, listener)
Listen a single custom event or multi custom events.
ptero.on('eventname', e => {
console.log(e.detail)
})
ptero.on(['eventname1', 'eventname2'], e => {
console.log(e.detail)
})
ptero.removeListener(event, listener)
Stop listening a single custom event.
const listener = e => {
console.log(e.detail)
}
ptero.addListener('eventname', listener)
ptero.removeListener('eventname', listener)
ptero.off(event, listener)
Stop listening a single custom event or multi custom events.
const listener = e => {
console.log(e.detail)
}
ptero.on('eventname1', listener)
ptero.on(['eventname2', 'eventname3'], listener)
ptero.off('eventname1', listener)
ptero.off(['eventname2', 'eventname3'], listener)
ptero.emit(event, detail)
Dispatch a single custom event.
ptero.emit('eventname', { foo: 1 })
Development
$ yarn start # for development
$ yarn run build # for production
$ yarn test # run tests
License
MIT © Emoji Generator