
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@foundit/broadcasterjs
Advanced tools
A simple yet powerful pub/sub pattern javascript event bus
easy to use
framework agnostic
minimal footprint
optimised for SPA applications
unintrusive as a dependency
no own dependencies
Here you can report issues or contribute
No need to initialize separately. Import the 'broadcast' factory function and use to your hearts content.
npm install @foundit/broadcasterjs
import { broadcast } from '@foundit/broadcasterjs'
useEffect(() => {
return broadcast.on(['MYBROADCAST-ID', myFlagEmittedCallbackFunction])
}, [myFlagEmittedCallbackFunction])
broadcast.on()
returns a unsubscribe function which comes in handy when you want to cleanup on component unmount. If your listener handler function does not depend on the React component it is instanciated, in you can of course omit the return
to make it persist.
.on
- start a subscription.
const off() = broadcast.on([
'MYBROADCAST-ID',
({ detail }) => {
document.body.append(detail + ' ')
},
])
.once
- start a subscription but cancel subscription after first emission.
const off() = broadcast.once([
'MYBROADCAST-ID',
({ detail }) => {
document.body.append(detail + ' ')
},
])
Call the return function to cancel a subscription.
off() // Use the subscribers return function.
Publish (emit) an event with a string payload.
broadcast.emit('MYBROADCAST-ID', 'Hello world')
Add ?debug=broadcasterjs
to your url and open your devtools console. Normally it shold be enough with inspecting comment node as described above.
The broadcaster functions on
,once
takes an optional third value and emit
takes an optional third argument in the form of a settings object.
{
debug: boolean (false)
debugGlobal: boolean (false)
allowDoublettesSubscribers: boolean (false)
useLatestSubscriberScope?: boolean (false) // <- internal use
suppresDebug?: boolean (false) // <- internal use
}
v 1.1.2 The common js version was not previously updated and did not return the unsubscribe function. It would then still behave as pre v1.1.0. v 1.1.1 v 1.1.0 The subscribe functions 'on' and 'once' now return a unsubscribe function (no arguments) that is much more user friendly than the previous off function. 'off' is still available but removed from the documentation.
Develop: yarn start
Compile typescript: tsc
Build out esm/cjs dist: npm run build
Publish to npm: npm publish --access=public
FAQs
A simple yet powerful pub/sub pattern javascript event bus
The npm package @foundit/broadcasterjs receives a total of 101 weekly downloads. As such, @foundit/broadcasterjs popularity was classified as not popular.
We found that @foundit/broadcasterjs 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.