Skip to content

Latest commit

 

History

History
111 lines (82 loc) · 2.29 KB

README.md

File metadata and controls

111 lines (82 loc) · 2.29 KB

ptero

npm build License

🌳 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 })

Features

  • Supports TypeScript
  • Supports both CommonJS and ESModules

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