Socket
Socket
Sign inDemoInstall

suub

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

suub

A simple pub/sub written in Typescript


Version published
Weekly downloads
7
increased by16.67%
Maintainers
1
Weekly downloads
 
Created
Source

suub logo

📫 Suub

A simple pub/sub written in Typescript

Gist

import { Subscription } from '../dist';

const mySub = Subscription.create<number>();

const unsub = mySub.subscribe(num => {
  console.log('num: ' + name);
});

mySub.call(45); // num: 45

unsub();

Examples

Take a look at the Examples folder.

API

Subscription.create(options: Options): Subscription

Create a new Subscription

  • options.onFirstSubscription?: A function called when the subscriber count goes from 0 to 1
  • options.onLastUnsubscribe?: A function called when the subscriber count goes from 1 to 0

Note: by default the T type is void meaning the Subscription has no data.

Subscription

A subscription object

Subscription.subscribe([subId, ] listener): Unsubscribe

Add a subscriber

  • subId (optional): Associate an id with the listener to be able to unsubscribe by this same id.
  • listener: The function that will be called when you call, this function receive a value as parameter (of type T)
  • return Unsubscribe: returns a function that will unsubscribe the listener.

Subscription.call(value: T)

Call all listeners in the same order they were subscribed

  • value: The value (of type T) that will be passed to the listeners

Note: If T is void this function does not take any arguments.

Subscription.unsubscribeAll()

Unsubscribe all listeners

Subscription.unsubscribe(listener)

Unsubscribe a listener either by reference or by id

  • listener: Either an id (string) or a reference to a listener

Subscription.isSubscribed(listener): boolean

Test wether a listener id subscribed or not

  • listener: Either an id (string) or a reference to a listener

Keywords

FAQs

Package last updated on 20 Oct 2019

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