Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jaandrle/fpubsub
PubSub pattern library with types support
https://github.com/jaandrle/fpubsub
event event-emitter functional-programming javascript pub-sub pubsub reactive reactive-programming typescript
Last synced: about 1 month ago
JSON representation
PubSub pattern library with types support
- Host: GitHub
- URL: https://github.com/jaandrle/fpubsub
- Owner: jaandrle
- License: mit
- Created: 2023-01-03T14:42:02.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-01-25T11:55:47.000Z (about 2 years ago)
- Last Synced: 2024-12-17T00:28:51.282Z (about 1 month ago)
- Topics: event, event-emitter, functional-programming, javascript, pub-sub, pubsub, reactive, reactive-programming, typescript
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/fpubsub
- Size: 99.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# fpubsub – PubSub implementation
This is the JavaScript implementation of the **PubSub** pattern in *JavaScript* for beeing used in functional programming approach.```js
/** @type {fpubsubTopic} */
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](./examples)
- [Guide](#guide)
- [Documentation](./docs/README.md) (generated from TypeScript)## Guide
See [Publish–subscribe pattern - Wikipedia](https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern) to more information about PubSub pattern.You can use library as regular npm package.
```bash
npm install fpubsub --save
```
```js
import { topic, subscribe, publish } from "fpubsub";
/** @type {fpubsubTopic} */
const onexample= topic();
subscribe(onexample, console.log);
publish(onexample, "Publish info to `onexample` topic.");
```Library exports:
- functions:
- [`topic`](./docs/README.md#topic): to generate event/topic
- you can also use with options `{ once, cache, initial, mapper }`, see [in docs](./docs/README.md#topicoptions)
- `topicFrom` – see [#7](https://github.com/jaandrle/fpubsub/issues/7)
- [`subscribe`](./docs/README.md#subscribe) (alias: `sub`): to subscribe topics
- [`publish`](./docs/README.md#publish) (alias: `pub`): to publish messages to the given topic
- [`unsubscribe`](./docs/README.md#unsubscribe) (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)](./docs/README.md)
## See also
- [yamiteru/ueve: 🔥 Hellishly fast and 🤏 tiny async/sync event emitter](https://github.com/yamiteru/ueve)
- [pubsub - npm search](https://www.npmjs.com/search?q=pubsub)
- [emit - npm search](https://www.npmjs.com/search?q=emit)