Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ianwalter/subpub
A super-simple JavaScript Subscribe/Publish (pubsub) implementation
https://github.com/ianwalter/subpub
events pattern-matching pubsub
Last synced: 6 days ago
JSON representation
A super-simple JavaScript Subscribe/Publish (pubsub) implementation
- Host: GitHub
- URL: https://github.com/ianwalter/subpub
- Owner: ianwalter
- License: other
- Created: 2018-10-20T03:30:24.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-10-17T17:03:06.000Z (about 1 year ago)
- Last Synced: 2024-11-02T01:23:04.817Z (about 2 months ago)
- Topics: events, pattern-matching, pubsub
- Language: JavaScript
- Homepage:
- Size: 672 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# @ianwalter/subpub
> A super-simple JavaScript Subscribe/Publish (pubsub) implementation[![npm page][npmImage]][npmUrl]
## Installation
```console
yarn add @ianwalter/subpub
```## Usage
```js
import { Subpub } from '@ianwalter/subpub'// Create a Subpub instance.
const sp = new Subpub()// Create a subscription to a topic.
const usubscribe = sp.sub('alerts', msg => console.log(msg))// Publish a message on the topic.
sp.pub('alerts', 'We ran out of coffee!')// Unsubscribe the subscriber from the topic.
usubscribe()// Create a subscriber with an object key that can be pattern-matched.
sp.sub({ key: '1d', name: 'BIBA' }, async msg => msg.toUpperCase())// Send a message to the subscriber using only the key property to match and
// wait for the returned promise to resolve with the transformed value.
await sp.pub({ key: '1d' }, 'Te biba nachdi') // => TE BIBA NACHDI
```## License
Apache 2.0 with Commons Clause - See [LICENSE][licenseUrl]
Created by [Ian Walter](https://ianwalter.dev)
[npmImage]: https://img.shields.io/npm/v/@ianwalter/subpub.svg
[npmUrl]: https://www.npmjs.com/package/@ianwalter/subpub
[licenseUrl]: https://github.com/ianwalter/subpub/blob/master/LICENSE