Security News
The Dark Side of Open Source
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
brcast
Advanced tools
Changelog
Readme
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.
This project uses node and npm. Go check them out if you don't have them locally installed.
$ npm install --save brcast
Then with a module bundler like rollup or webpack, use as you would anything else:
// using ES6 modules
import brcast from 'brcast'
// using CommonJS modules
var brcast = require('brcast')
The UMD build is also available on unpkg:
<script src="https://unpkg.com/brcast/dist/brcast.umd.js"></script>
You can find the library on window.brcast
.
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)
brcast([initialState])
Creates a broadcast
object.
1 - [initialState
] (any): The initial state.
(broadcast
): An object that holds the state.
broadcast.setState(state)
Store the new state.
1 - state
(any): The new state.
Nothing.
broadcast.getState()
Get the stored state.
(Any
): The stored state.
broadcast.subscribe(handler)
Subscribe to state changes.
1 - handler
(Function): The callback to be invoked any time the state changes.
(Number
): The subscription id to be used to unsubscribe.
broadcast.unsubscribe(subscriptionId)
Unsubscribe the change listener.
1 - subscriptionId
(Number): The subscription id returned by subscribing.
Nothing.
$ npm run test
FAQs
Tiny data broadcaster with 0 dependencies
The npm package brcast receives a total of 569,877 weekly downloads. As such, brcast popularity was classified as popular.
We found that brcast demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
Research
Security News
The Socket Research team found this npm package includes code for collecting sensitive developer information, including your operating system username, Git username, and Git email.
Security News
OpenJS is warning of social engineering takeovers targeting open source projects after receiving a credible attempt on the foundation.