Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@foundit/broadcasterjs

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@foundit/broadcasterjs

A simple yet powerful pub/sub javascript event bus

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
107
decreased by-13.71%
Maintainers
1
Weekly downloads
 
Created
Source

broadcasterjs

A simple yet powerful pub/sub javascript event bus
  • easy to use
  • framework agnostic
  • unintrusive as a dependency
  • minimal footprint
  • optimised for SPA applications

Demo app available


Usage

No need to initialize separately. Import the 'broadcast' factory function and use to your hearts content.

START SUBSCRIPTION IN REACT
useEffect(() => {
  broadcast.on(['BROADCAST-ID', flagReceivedFunction])
}, [flagReceivedFunction])
START SUBSCRIPTION VANILLA JS
broacaster.on([
  'BROADCAST-ID',
  ({ detail }) => {
    document.body.append(detail + ' ')
  },
])
broacaster.once([
  'BROADCAST-ID',
  ({ detail }) => {
    document.body.append(detail + ' ')
  },
])
END SUBSCRIPTION
broacaster.off([
  'BROADCAST-ID',
  ({ detail }) => {
    document.body.append(detail + ' ')
  },
])
PUBLISH IN REACT & VANILLLA JS
broadcast.emit('BROADCAST-ID', 'Hello world')
TO VISUALLY INSPECT

Click elements tab i chrome devtools, select event-listeners tab in second pane. Active listeners begin with 'broadcast-' + flag name. Expand each listener to see each unique subscriber.

TO DEBUG

Add ?debug=broadcasterjs to your url and open your devtools console.

ADVANCED

The broadcaster functions on,once,off takes an optional third value and emit takes an optional third argument in the form of a settings object.

{
  debug: boolean
  debugGlobal: boolean
  allowDoublettesSubscribers: boolean
}

Broadcasterjs does prevent doublettes with the same subscriber combination (flag + callback function). If you for some reason would want the same combination on another place in the code either just add a minor change, a comment etc or send in the settings object with allowDoublettesSubscribers set to true.

Keywords

FAQs

Package last updated on 05 Feb 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc