bubbly

1.1.2 • Public • Published

bubbly

Travis CI npm npm

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

See Also

Dependencies (0)

    Dev Dependencies (9)

    Package Sidebar

    Install

    npm i bubbly

    Weekly Downloads

    0

    Version

    1.1.2

    License

    ISC

    Last publish

    Collaborators

    • eddiemoore
    • migbuild
    • seb