Commit 856d88afbef69775a9d80aca2652a45f598a0163
extract mutant-pull-reduce to own package
Matt McKegg committed on 2/15/2017, 12:14:11 PMParent: d092b707950e5fda7d051ad6913a8cbd99c22955
Files changed
lib/mutant-pull-reduce.js | deleted |
modules/channel/obs/subscribed.js | changed |
modules/profile/obs/following.js | changed |
modules/profile/obs/recently-updated.js | changed |
package.json | changed |
lib/mutant-pull-reduce.js | ||
---|---|---|
@@ -1,55 +1,0 @@ | ||
1 | -var pullPause = require('pull-pause') | |
2 | -var Value = require('mutant/value') | |
3 | -var LazyWatcher = require('mutant/lib/lazy-watcher') | |
4 | - | |
5 | -var pull = require('pull-stream') | |
6 | - | |
7 | -module.exports = function (stream, reducer, opts) { | |
8 | - var pauser = pullPause((paused) => {}) | |
9 | - var seq = 0 | |
10 | - var lastSeq = -1 | |
11 | - pauser.pause() | |
12 | - | |
13 | - var binder = LazyWatcher(update, pauser.resume, pauser.pause) | |
14 | - var result = function MutantPullReduce (listener) { | |
15 | - if (!listener) { | |
16 | - return binder.getValue() | |
17 | - } | |
18 | - return binder.addListener(listener) | |
19 | - } | |
20 | - | |
21 | - binder.value = opts.startValue | |
22 | - binder.nextTick = opts.nextTick | |
23 | - result.sync = Value(false) | |
24 | - | |
25 | - pull( | |
26 | - stream, | |
27 | - pauser, | |
28 | - pull.drain((item) => { | |
29 | - if (item.sync) { | |
30 | - result.sync.set(true) | |
31 | - } else { | |
32 | - seq += 1 | |
33 | - binder.value = reducer(binder.value, item) | |
34 | - binder.onUpdate() | |
35 | - } | |
36 | - }) | |
37 | - ) | |
38 | - | |
39 | - return result | |
40 | - | |
41 | - // scoped | |
42 | - | |
43 | - function update () { | |
44 | - if (!binder.live) { | |
45 | - // attempt to push through sync changes | |
46 | - pauser.resume() | |
47 | - pauser.pause() | |
48 | - } | |
49 | - | |
50 | - if (lastSeq !== seq) { | |
51 | - seq = lastSeq | |
52 | - return true | |
53 | - } | |
54 | - } | |
55 | -} |
modules/channel/obs/subscribed.js | ||
---|---|---|
@@ -1,7 +1,7 @@ | ||
1 | 1 | var pull = require('pull-stream') |
2 | 2 | var computed = require('mutant/computed') |
3 | -var MutantPullReduce = require('../../../lib/mutant-pull-reduce') | |
3 | +var MutantPullReduce = require('mutant-pull-reduce') | |
4 | 4 | var nest = require('depnest') |
5 | 5 | |
6 | 6 | var throttle = require('mutant/throttle') |
7 | 7 |
modules/profile/obs/following.js | ||
---|---|---|
@@ -1,7 +1,7 @@ | ||
1 | 1 | var pull = require('pull-stream') |
2 | 2 | var computed = require('mutant/computed') |
3 | -var MutantPullReduce = require('../../../lib/mutant-pull-reduce') | |
3 | +var MutantPullReduce = require('mutant-pull-reduce') | |
4 | 4 | var throttle = require('mutant/throttle') |
5 | 5 | var nest = require('depnest') |
6 | 6 | |
7 | 7 | exports.needs = nest({ |
modules/profile/obs/recently-updated.js | ||
---|---|---|
@@ -1,8 +1,8 @@ | ||
1 | 1 | var pull = require('pull-stream') |
2 | 2 | var pullCat = require('pull-cat') |
3 | 3 | var computed = require('mutant/computed') |
4 | -var MutantPullReduce = require('../../../lib/mutant-pull-reduce') | |
4 | +var MutantPullReduce = require('mutant-pull-reduce') | |
5 | 5 | var throttle = require('mutant/throttle') |
6 | 6 | var nest = require('depnest') |
7 | 7 | var hr = 60 * 60 * 1000 |
8 | 8 |
package.json | ||
---|---|---|
@@ -28,8 +28,9 @@ | ||
28 | 28 | "level": "~1.4.0", |
29 | 29 | "level-memview": "0.0.0", |
30 | 30 | "micro-css": "^1.0.0", |
31 | 31 | "mutant": "^3.14.0", |
32 | + "mutant-pull-reduce": "^1.0.0", | |
32 | 33 | "non-private-ip": "^1.4.1", |
33 | 34 | "on-change-network": "0.0.2", |
34 | 35 | "on-wakeup": "^1.0.1", |
35 | 36 | "prebuild": "github:mmckegg/prebuild#use-npm-conf", |
Built with git-ssb-web