https://github.com/32bitkid/kefir.scanbytype
A tiny abstraction to help use Kefir Observables for a flux-like pattern
https://github.com/32bitkid/kefir.scanbytype
Last synced: 5 months ago
JSON representation
A tiny abstraction to help use Kefir Observables for a flux-like pattern
- Host: GitHub
- URL: https://github.com/32bitkid/kefir.scanbytype
- Owner: 32bitkid
- License: isc
- Created: 2017-01-28T17:43:16.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-03-13T17:28:30.000Z (over 9 years ago)
- Last Synced: 2025-09-23T19:58:19.856Z (9 months ago)
- Language: JavaScript
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# kefir.scanbytype
A tiny abstraction to help use [Kefir](https://rpominov.github.io/kefir/#scan) Observables for a flux-like pattern.
## Installation
### NPM
```
npm install kefir.scanbytype
```
## Usage
```js
import Kefir from 'kefir';
import scanByType from 'kefir.scanbytype';
var libraryEvents = [
{ type: 'CHECKOUT', title: 'The Cat in the Hat' },
{ type: 'TRANSFER_IN', title: 'Green Eggs and Ham' },
{ type: 'RETURN', title: 'The Lorax' },
{ type: 'CHECKOUT', title: 'Green Eggs and Ham' },
];
var initialState = {};
var reducer = scanByType({
CHECKOUT: (state, data) => { /* checkout logic */ },
RETURN: (state, data) => { /* return logic */ },
TRANSFER_IN: (state, data) => { /* transfer in logic */ },
TRANSFER_OUT: (state, data) => { /* transfer out logic */ },
});
Kefir.sequentially(1000, events)
.scan(reducer, initialState)
.log();
```
### With ES7 `::` bind operator
```
import { scanByType } from 'kefir.scanByType';
var initalState = {};
var source = Kefir.sequentially(100, [0, 1, 2, 3]);
var result = source::scanByType({
CHECKOUT(state, data) {
return state;
},
}, initialState)
```