weak-bubble

2.1.0 • Public • Published

weak-bubble Build Status

Bubble weakmap-events up without explicit re-broadcasting

Install

$ npm install --save weak-bubble

Usage

var event = require('weakmap-event')()
var bubble = require('weak-bubble')
var state = {
  foo: {}
}

var listen = bubble({foo: event.listen})
listen(state, function (data) {
  //=> 'DATA!'
})
event.broadcast(state.foo, 'DATA!')

API

bubble(listeners, [transform]) -> function

listeners

Required
Type: object

An object where the keys represent keys in your object and the values are the listen functions from a weakmap-event.

transform

Type: function
Arguments: state, data

An optional function called with the state and event data. By default, the event data is forwarded up. By passing in a function, you can add or remove properties or return entirely different data.

If you return false, the listeners will not be called.

License

MIT © Ben Drucker

Package Sidebar

Install

npm i weak-bubble

Weekly Downloads

0

Version

2.1.0

License

MIT

Last publish

Collaborators

  • bendrucker