Files: 1e97e10c01b52d7913be252f773d767c69120bcf / modules / progress / html / peer.js
900 bytesRaw
1 | var {computed, when} = require('mutant') |
2 | var nest = require('depnest') |
3 | |
4 | exports.gives = nest('progress.html.peer') |
5 | |
6 | exports.needs = nest({ |
7 | 'progress.html.render': 'first', |
8 | 'progress.obs.peer': 'first', |
9 | 'progress.obs.global': 'first' |
10 | }) |
11 | |
12 | exports.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