Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including bubbly with all npm packages installed. Try it out:

var bubbly = require("bubbly")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

bubbly v1.1.2

Shorthand for event handling


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.


npm install --save bubbly


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'

off(type, handler)

Alias for removeEventListener.

import {off} from 'bubbly'

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')


Run tests

npm test


mocha --watch

See Also

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free