git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Commit 851f7cc94921a9a86c3caca8bba86c375ddd09b5

make status updates less flickery

Matt McKegg committed on 3/13/2017, 5:13:43 AM
Parent: e7b3657966e1482fd0d40fc94ffb793304ac0c17

Files changed

lib/sustained.jsadded
modules/app/html/progress-notifier.jschanged
lib/sustained.jsView
@@ -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.jsView
@@ -1,6 +1,7 @@
11 var {computed, when, h, throttle} = require('mutant')
22 var nest = require('depnest')
3+var sustained = require('../../../lib/sustained')
34
45 exports.gives = nest('app.html.progressNotifier')
56
67 exports.needs = nest({
@@ -44,9 +45,9 @@
4445 return incomplete > 10
4546 }
4647 })
4748
48- return h('div.info', { hidden: throttle(hidden, 5000) }, [
49+ return h('div.info', { hidden: sustained(hidden, 1000) }, [
4950 h('div.status', [
5051 h('Loading -small', [
5152 when(hasDownloadProgress,
5253 ['Downloading new messages', h('progress', { style: {'margin-left': '10px'}, min: 0, max: 1, value: downloadProgress })],

Built with git-ssb-web