Observable subject event bus


Keywords
flexbase, observable, subject, event-bus, event, bus
License
MIT
Install
npm install @flexbase/observable-subject@2.1.2

Documentation

observable-subject

Coverage Quality Gate Status

Observable subject event bus

Installation

npm install @flexbase/observable-subject

or

yarn add @flexbase/observable-subject

Usage

import { Subject, subjectManager } from '@flexbase/observable-subject';

// create a subject
const subject: Subject = { key: Symbol() };

// register the subject
await subjectManager.register(subject);

// subscribe to the subject
const subscription = subjectManager.subscribe<number>(subject, async context => {
  await new Promise(_ => setTimeout(_, context.value));
});

// notify subscriptions
await subjectManager.notify(subject, { value: 1000 });

// unsubscribe
subscription.unsubscribe();