@flexbase/observable-subject
v2.1.2
Published
Observable subject event bus
Downloads
36
Readme
observable-subject
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();