https://github.com/jamiemason/glob-bus
249 byte event emitter / pubsub with namespaced wildcards.
https://github.com/jamiemason/glob-bus
event event-bus event-handlers event-listener eventbus eventemitter events listener mitt pub-sub publish pubsub subscribe typescript
Last synced: about 2 months ago
JSON representation
249 byte event emitter / pubsub with namespaced wildcards.
- Host: GitHub
- URL: https://github.com/jamiemason/glob-bus
- Owner: JamieMason
- License: mit
- Created: 2011-03-18T09:15:23.000Z (about 14 years ago)
- Default Branch: master
- Last Pushed: 2022-01-02T20:29:34.000Z (over 3 years ago)
- Last Synced: 2024-10-24T01:32:48.344Z (6 months ago)
- Topics: event, event-bus, event-handlers, event-listener, eventbus, eventemitter, events, listener, mitt, pub-sub, publish, pubsub, subscribe, typescript
- Language: TypeScript
- Homepage: https://github.com/JamieMason/glob-bus
- Size: 14 MB
- Stars: 10
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# glob-bus
249 byte pub/sub event bus with namespaced wildcard support.
[](https://www.npmjs.com/package/glob-bus)
[](https://www.npmjs.com/package/glob-bus)
[](https://github.com/JamieMason)
[](https://twitter.com/fold_left)## Installation
```
npm install --save glob-bus
```## Example
In this example, all three listeners will be invoked.
```ts
import { globBus } from 'glob-bus';type Event =
| { type: 'basket.product.add'; id: number }
| { type: 'basket.product.remove'; id: number };const { on, send } = globBus();
on('*', (event: Event) => console.log(1, event));
on('basket.*', (event: Event) => console.log(2, event));
on('basket.product.*', (event: Event) => console.log(3, event));send({ type: 'basket.product.add', id: 123 });
```The `on` function returns a function to unregister the given listener:
```ts
import { globBus } from 'glob-bus';const { on, send } = globBus();
const off = on('basket.product.*', fn);off();
```