https://github.com/bendrucker/weak-bubble
Bubble weakmap-events up without explicit re-broadcasting
https://github.com/bendrucker/weak-bubble
Last synced: over 1 year ago
JSON representation
Bubble weakmap-events up without explicit re-broadcasting
- Host: GitHub
- URL: https://github.com/bendrucker/weak-bubble
- Owner: bendrucker
- License: mit
- Created: 2015-08-03T22:42:37.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2019-08-19T21:47:54.000Z (almost 7 years ago)
- Last Synced: 2025-04-10T08:14:08.753Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 10.7 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# weak-bubble [](https://travis-ci.org/bendrucker/weak-bubble) [](https://greenkeeper.io/)
> Bubble weakmap-events up without explicit re-broadcasting
## Install
```
$ npm install --save weak-bubble
```
## Usage
```js
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](https://github.com/eaze/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](http://bendrucker.me)