1.0.0 • Published 1 year ago
fpubsub v1.0.0
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/topic - you can also use with options{ once, cache, initial, mapper }
, see in docs -topicFrom
– see #7 -subscribe
(alias:sub
): to subscribe topics -publish
(alias:pub
): to publish messages to the given topic -unsubscribe
(alias:unsub
): to remove topics listeners - another helpers:unsubscribeAll
,has
,erase
,isTopic
,valueOf
- types:
-
Topic
: to anote you TypeScript topic - orfpubsubTopic
: as global type for anotating topics in JavaScript (JSDoc)
…see Documentation (generated from TypeScript)