weak-bubble
v2.1.0
Published
Bubble weakmap-events up without explicit re-broadcasting
Downloads
6
Maintainers
Readme
weak-bubble
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