Tiny data broadcaster with 0 dependencies
npm install brcast> Tiny data broadcaster with 0 dependencies







The current size of brcast/dist/brcast.umd.min.js is:

It's like a data store you can subscribe to, with a setter to pump data in.
For browsers and node.
- Install
- Usage
- API
- Testing
- License
This project uses node and npm. Go check them out if you don't have them locally installed.
``sh`
$ npm install --save brcast
Then with a module bundler like rollup or webpack, use as you would anything else:
`javascript
// using ES6 modules
import brcast from 'brcast'
// using CommonJS modules
var brcast = require('brcast')
`
The UMD build is also available on unpkg:
`html`
You can find the library on window.brcast.
`js
import brcast from 'brcast'
let broadcast = brcast()
// subscribe
const subscriptionId = broadcast.subscribe(state => console.log(state))
// setState sets the state and invoke all subscription callbacks passing in the state
broadcast.setState(1)
// setState returns the current state
broadcast.getState()
// unsubscribe to unbind the handler
broadcast.unsubscribe(subscriptionId)
`
Creates a broadcast object.
#### Arguments
1 - [initialState] (any): The initial state.
#### Returns
(broadcast): An object that holds the state.
Store the new state.
#### Arguments
1 - state (any): The new state.
#### Returns
Nothing.
Get the stored state.
#### Returns
(Any): The stored state.
Subscribe to state changes.
#### Arguments
1 - handler (Function): The callback to be invoked any time the state changes.
#### Returns
(Number): The subscription id to be used to unsubscribe.
Unsubscribe the change listener.
#### Arguments
1 - subscriptionId (Number): The subscription id returned by subscribing.
#### Returns
Nothing.
`sh``
$ npm run test