fpubsub
v1.0.0
Published
PubSub pattern library with types support
Downloads
6
Maintainers
Readme
fpubsub – PubSub implementation
This is the JavaScript implementation of the PubSub pattern in JavaScript for beeing used in functional programming approach.
/** @type {fpubsubTopic<string>} */
const onexample= topic();
subscribe(onexample, console.log);
subscribe(onexample)(console.log);
subscribe(console.log)(onexample);
publish(onexample, "Publish info to `onexample` topic.");
publish.bind(null, onexample)("Publish info to `onexample` again.");
publish("Publish info to `onexample` last time.")(onexample);
Quick links
- Examples: see folder ./examples
- Guide
- Documentation (generated from TypeScript)
Guide
See Publish–subscribe pattern - Wikipedia to more information about PubSub pattern.
You can use library as regular npm package.
npm install fpubsub --save
import { topic, subscribe, publish } from "fpubsub";
/** @type {fpubsubTopic<string>} */
const onexample= topic();
subscribe(onexample, console.log);
publish(onexample, "Publish info to `onexample` topic.");
Library exports:
- functions:
topic
: to generate event/topicsubscribe
(alias:sub
): to subscribe topicspublish
(alias:pub
): to publish messages to the given topicunsubscribe
(alias:unsub
): to remove topics listeners- another helpers:
unsubscribeAll
,has
,erase
,isTopic
,valueOf
- types:
Topic
: to anote you TypeScript topic- or
fpubsubTopic
: as global type for anotating topics in JavaScript (JSDoc)
…see Documentation (generated from TypeScript)