https://github.com/nichoth/pull-store
State machine as a pull stream
https://github.com/nichoth/pull-store
Last synced: about 2 months ago
JSON representation
State machine as a pull stream
- Host: GitHub
- URL: https://github.com/nichoth/pull-store
- Owner: nichoth
- Created: 2016-11-21T18:41:37.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-04-05T01:33:26.000Z (over 9 years ago)
- Last Synced: 2025-10-01T11:53:26.049Z (10 months ago)
- Language: JavaScript
- Homepage: https://github.com/nichoth/pull-store#readme
- Size: 6.84 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# pull store
State machine as a pull stream
## install
$ npm install pull-store
## example
```js
var test = require('tape')
var S = require('pull-stream')
var Store = require('../')
var store = Store(function (acc, n) {
return n
}, 0)
test('store', function (t) {
t.plan(1)
S(
S.values([1,2,3]),
store(),
S.collect(function (err, res) {
t.deepEqual(res, [0,1,2,3], 'should emit initial state')
})
)
})
test('subscribe again', function (t) {
t.plan(1)
S(
S.values([4,5]),
store(),
S.collect(function (err, res) {
t.deepEqual(res, [3,4,5], 'should keep state after a stream ends')
})
)
})
```
multiple subscribers
```js
test('multiple subscribers', function (t) {
t.plan(4)
var store = Store(function (acc, n) {
return n
}, 5)
S(
store.state(), // return a source stream starting with the latest value
S.collect(function (err, res) {
t.error(err)
t.deepEqual(res, [5,6,7,8], 'we can listen over here too')
})
)
S(
S.values([6,7,8]),
store(),
S.collect(function (err, res) {
t.error(err)
t.deepEqual(res, [5,6,7,8])
})
)
store.end()
})
```