git ssb

1+

Daan Patchwork / patchwork



Tree: 58ab0241031aa549a35cce1e678c27065ae66221

Files: 58ab0241031aa549a35cce1e678c27065ae66221 / lib / plugins / progress.js

647 bytesRaw
1const Pushable = require('pull-pushable')
2const deepEqual = require('deep-equal')
3
4module.exports = function (ssb) {
5 return {
6 stream: function () {
7 let lastValue = deepClone(ssb.progress())
8
9 const timer = setInterval(() => {
10 const newValue = ssb.progress()
11 if (!deepEqual(newValue, lastValue)) {
12 lastValue = deepClone(newValue)
13 pushable.push(lastValue)
14 }
15 }, 200)
16
17 const pushable = Pushable(() => {
18 clearInterval(timer)
19 })
20
21 pushable.push(lastValue)
22 return pushable
23 }
24 }
25}
26
27function deepClone (obj) {
28 return JSON.parse(JSON.stringify(obj))
29}
30

Built with git-ssb-web