git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: 97eb203c6049b5a49935be9ffca99fe8fbd07188

Files: 97eb203c6049b5a49935be9ffca99fe8fbd07188 / lib / progress-stream.js

771 bytesRaw
1var Pushable = require('pull-pushable')
2var deepEqual = require('deep-equal')
3
4exports.name = 'progressStream'
5exports.version = require('../package.json').version
6exports.manifest = {
7 read: 'source'
8}
9
10exports.init = function (ssb, config) {
11 return {
12 read: function (opts) {
13 var lastValue = deepClone(ssb.progress())
14
15 var timer = setInterval(() => {
16 var newValue = ssb.progress()
17 if (!deepEqual(newValue, lastValue)) {
18 lastValue = deepClone(newValue)
19 pushable.push(lastValue)
20 }
21 }, 200)
22
23 var pushable = Pushable(() => {
24 clearInterval(timer)
25 })
26
27 pushable.push(lastValue)
28 return pushable
29 }
30 }
31}
32
33function deepClone (obj) {
34 return JSON.parse(JSON.stringify(obj))
35}
36

Built with git-ssb-web