Commit 851f7cc94921a9a86c3caca8bba86c375ddd09b5
make status updates less flickery
Matt McKegg committed on 3/13/2017, 5:13:43 AMParent: e7b3657966e1482fd0d40fc94ffb793304ac0c17
Files changed
lib/sustained.js | added |
modules/app/html/progress-notifier.js | changed |
lib/sustained.js | ||
---|---|---|
@@ -1,0 +1,29 @@ | ||
1 | +var watch = require('mutant/watch') | |
2 | +var computed = require('mutant/computed') | |
3 | +var Value = require('mutant/value') | |
4 | + | |
5 | +module.exports = Sustained | |
6 | + | |
7 | +// only broadcast value changes once a truthy value has stayed constant for more than timeThreshold | |
8 | + | |
9 | +function Sustained (obs, timeThreshold) { | |
10 | + var outputValue = Value(obs()) | |
11 | + | |
12 | + return computed(outputValue, v => v, { | |
13 | + onListen: () => watch(obs, onChange) | |
14 | + }) | |
15 | + | |
16 | + function onChange (value) { | |
17 | + if (!value) { // update immediately for falsy values | |
18 | + clearTimeout() | |
19 | + update() | |
20 | + } else if (value !== outputValue()) { | |
21 | + clearTimeout() | |
22 | + setTimeout(update, timeThreshold) | |
23 | + } | |
24 | + } | |
25 | + | |
26 | + function update () { | |
27 | + outputValue.set(obs()) | |
28 | + } | |
29 | +} |
modules/app/html/progress-notifier.js | ||
---|---|---|
@@ -1,6 +1,7 @@ | ||
1 | 1 | var {computed, when, h, throttle} = require('mutant') |
2 | 2 | var nest = require('depnest') |
3 | +var sustained = require('../../../lib/sustained') | |
3 | 4 | |
4 | 5 | exports.gives = nest('app.html.progressNotifier') |
5 | 6 | |
6 | 7 | exports.needs = nest({ |
@@ -44,9 +45,9 @@ | ||
44 | 45 | return incomplete > 10 |
45 | 46 | } |
46 | 47 | }) |
47 | 48 | |
48 | - return h('div.info', { hidden: throttle(hidden, 5000) }, [ | |
49 | + return h('div.info', { hidden: sustained(hidden, 1000) }, [ | |
49 | 50 | h('div.status', [ |
50 | 51 | h('Loading -small', [ |
51 | 52 | when(hasDownloadProgress, |
52 | 53 | ['Downloading new messages', h('progress', { style: {'margin-left': '10px'}, min: 0, max: 1, value: downloadProgress })], |
Built with git-ssb-web