https://github.com/whiteinge/rx-bytag
An RxJS operator to provide very lightweight "channels"
https://github.com/whiteinge/rx-bytag
Last synced: 10 months ago
JSON representation
An RxJS operator to provide very lightweight "channels"
- Host: GitHub
- URL: https://github.com/whiteinge/rx-bytag
- Owner: whiteinge
- Created: 2016-09-05T16:22:10.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-09-23T22:33:24.000Z (over 9 years ago)
- Last Synced: 2025-03-01T01:41:17.469Z (11 months ago)
- Language: JavaScript
- Size: 7.81 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# rx-byTag
An RxJS operator to provide very lightweight "channels".
This wraps the Rx
[filter](https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/operators/where.md)
operator to perform succinct matching using light shell-style glabbing syntax.
The whole package consists of three, small functions.
This provides two things:
* A lightweight way to create a "by convention channel" in an Rx stream by sending an object payload with a `tag` attribute.
* A very lightweight hierarchical namespacing syntax using simple strings. Each "level" in the slash-delimited string provides an additional level of specificity.
## Example
```js
import {byTag, sendAction} from 'rx-bytag';
Rx.Observable.prototype.byTag = byTag;
var Dispatcher = new Rx.Subject();
var send = sendAction.bind(Dispatcher);
var sub = Dispatcher.byTag('foo/*/baz')
.subscribe(x => console.log(x);
send('foo/bar/baz', {bar: 'Bar'});
// => {tag: 'foo/bar/baz', data: {bar: 'Bar'}}
// With currying for easy use in callbacks.
send('foo/bar/baz')({bar: 'Bar'});
// => {tag: 'foo/bar/baz', data: {bar: 'Bar'}}
```
## Related Projects
* The [Rxmq.js](https://github.com/rxmqjs/rxmq.js) project provides much more robust channel functionality and uses a far more granular filtering syntax.