Nitrogenous Polymorphic Molecule

npm

Check out our latest tech talk, "JavaScript Supply Chain Security" presented by VP of Security, Adam Baldwin.Watch it here »

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

install

npm i bubbly

Downloadsweekly downloads

32

version

1.1.2

license

ISC

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
  • avatar
  • avatar
Report a vulnerability