git ssb

10+

Matt McKegg / patchwork



Commit 856d88afbef69775a9d80aca2652a45f598a0163

extract mutant-pull-reduce to own package

Matt McKegg committed on 2/15/2017, 12:14:11 PM
Parent: d092b707950e5fda7d051ad6913a8cbd99c22955

Files changed

lib/mutant-pull-reduce.jsdeleted
modules/channel/obs/subscribed.jschanged
modules/profile/obs/following.jschanged
modules/profile/obs/recently-updated.jschanged
package.jsonchanged
lib/mutant-pull-reduce.jsView
@@ -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.jsView
@@ -1,7 +1,7 @@
11 var pull = require('pull-stream')
22 var computed = require('mutant/computed')
3-var MutantPullReduce = require('../../../lib/mutant-pull-reduce')
3 +var MutantPullReduce = require('mutant-pull-reduce')
44 var nest = require('depnest')
55
66 var throttle = require('mutant/throttle')
77
modules/profile/obs/following.jsView
@@ -1,7 +1,7 @@
11 var pull = require('pull-stream')
22 var computed = require('mutant/computed')
3-var MutantPullReduce = require('../../../lib/mutant-pull-reduce')
3 +var MutantPullReduce = require('mutant-pull-reduce')
44 var throttle = require('mutant/throttle')
55 var nest = require('depnest')
66
77 exports.needs = nest({
modules/profile/obs/recently-updated.jsView
@@ -1,8 +1,8 @@
11 var pull = require('pull-stream')
22 var pullCat = require('pull-cat')
33 var computed = require('mutant/computed')
4-var MutantPullReduce = require('../../../lib/mutant-pull-reduce')
4 +var MutantPullReduce = require('mutant-pull-reduce')
55 var throttle = require('mutant/throttle')
66 var nest = require('depnest')
77 var hr = 60 * 60 * 1000
88
package.jsonView
@@ -28,8 +28,9 @@
2828 "level": "~1.4.0",
2929 "level-memview": "0.0.0",
3030 "micro-css": "^1.0.0",
3131 "mutant": "^3.14.0",
32 + "mutant-pull-reduce": "^1.0.0",
3233 "non-private-ip": "^1.4.1",
3334 "on-change-network": "0.0.2",
3435 "on-wakeup": "^1.0.1",
3536 "prebuild": "github:mmckegg/prebuild#use-npm-conf",

Built with git-ssb-web