bubbly
v1.1.2
Published
Shorthand for event handling
Downloads
11
Readme
bubbly
Effortlessly create CustomEvent instances.
Trigger events on any object that implements the EventTarget interface.
Fits well with Custom Elements in Web Components based apps.
Designed to be used with ECMAScript Function Bind syntax.
Installation
npm install --save bubbly
Usage
dispatch(type, detail)
import {dispatch} from 'bubbly'
const target = new EventTarget()
target::dispatch('welcome', { hello: 'world' })
bubble(type, detail)
Like dispatch
but lets the event bubble up.
import {bubble} from 'bubbly'
document.body::bubble('shake', { dat: 'booty' })
on(type, handler)
Alias for addEventListener
.
import {on} from 'bubbly'
document::on('DOMContentLoaded', ::console.info)
off(type, handler)
Alias for removeEventListener
.
import {off} from 'bubbly'
document::off('DOMContentLoaded')
once(type, handler)
Wait for an event to fire, then stop listening.
import {once} from 'bubbly'
const anchor = document.createElement('a')
anchor::once('click', event => event.preventDefault())
Or treat an event like a Promise.
await anchor::once('click')
Development
Run tests
npm test
TDD
mocha --watch