Socket
Socket
Sign inDemoInstall

brcast

Package Overview
Dependencies
0
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    brcast

Tiny data broadcaster with 0 dependencies


Version published
Weekly downloads
591K
increased by5.89%
Maintainers
1
Install size
21.2 kB
Created
Weekly downloads
 

Changelog

Source

3.0.2 (2020-06-03)

Bug Fixes

  • Fix memory leak in unsubscribe (17af54d)

<a name="3.0.1"></a>

Readme

Source

Brcast

Tiny data broadcaster with 0 dependencies

Travis Code Coverage David npm npm JavaScript Style Guide MIT License

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

gzip size

It's like a data store you can subscribe to, with a setter to pump data in. For browsers and node.

Table of Contents

Install

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.

Usage

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)

API

brcast([initialState])

Creates a broadcast object.

Arguments

1 - [initialState] (any): The initial state.

Returns

(broadcast): An object that holds the state.

broadcast.setState(state)

Store the new state.

Arguments

1 - state (any): The new state.

Returns

Nothing.

broadcast.getState()

Get the stored state.

Returns

(Any): The stored state.

broadcast.subscribe(handler)

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.

broadcast.unsubscribe(subscriptionId)

Unsubscribe the change listener.

Arguments

1 - subscriptionId (Number): The subscription id returned by subscribing.

Returns

Nothing.

Tests

$ npm run test

MIT License © Alessandro Arnodo

Keywords

FAQs

Last updated on 03 Jun 2020

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc