Files: 55fc93a9190c25f467ead205ab8d676b5191dbd4 / lib / plugins / progress.js
846 bytesRaw
1 | const Pushable = require('pull-pushable') |
2 | const deepEqual = require('deep-equal') |
3 | |
4 | module.exports = function (ssb) { |
5 | return { |
6 | stream: function () { |
7 | let lastValue = deepClone(ssb.status()) |
8 | lastValue = { |
9 | ...lastValue.progress, |
10 | plugins: lastValue.sync.plugins, |
11 | } |
12 | |
13 | const timer = setInterval(() => { |
14 | let newValue = deepClone(ssb.status()) |
15 | newValue = { |
16 | ...newValue.progress, |
17 | plugins: newValue.sync.plugins, |
18 | } |
19 | if (!deepEqual(newValue, lastValue)) { |
20 | lastValue = newValue |
21 | pushable.push(lastValue) |
22 | } |
23 | }, 200) |
24 | |
25 | const pushable = Pushable(() => { |
26 | clearInterval(timer) |
27 | }) |
28 | |
29 | pushable.push(lastValue) |
30 | return pushable |
31 | } |
32 | } |
33 | } |
34 | |
35 | function deepClone (obj) { |
36 | return JSON.parse(JSON.stringify(obj)) |
37 | } |
38 |
Built with git-ssb-web