git ssb

10+

Matt McKegg / patchwork



Tree: 7538a3793f7fab7519df35f780b48398c0a9bbef

Files: 7538a3793f7fab7519df35f780b48398c0a9bbef / modules / progress / html / peer.js

900 bytesRaw
1var {computed, when} = require('mutant')
2var nest = require('depnest')
3
4exports.gives = nest('progress.html.peer')
5
6exports.needs = nest({
7 'progress.html.render': 'first',
8 'progress.obs.peer': 'first',
9 'progress.obs.global': 'first'
10})
11
12exports.create = function (api) {
13 return nest('progress.html.peer', function (id) {
14 var progress = api.progress.obs.peer(id)
15
16 var max = 0
17 var feeds = computed([api.progress.obs.global().feeds, progress], function (feeds, progress) {
18 // handle when feeds hasn't finished loading yet, take max from progress
19 if (progress) {
20 max = Math.max(max, feeds || 0, progress)
21 } else {
22 max = feeds
23 }
24 return max
25 })
26
27 var value = computed([progress, feeds], (pending, feeds) => {
28 return (feeds - pending) / feeds
29 })
30
31 return api.progress.html.render(value, when(progress, '-pending'))
32 })
33}
34

Built with git-ssb-web