Skip to content
💦 Shorthand for event handling
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
test
.babelrc
.editorconfig
.eslintignore
.eslintrc
.gitignore
.npmignore
.travis.yml
README.md
package.json

README.md

bubbly

Travis CI Dependency Status 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

You can’t perform that action at this time.