git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Commit afd57d9346079ee027e01d80b4d77a1dd2dba9fc

sustained: fix handling of changing values

Matt McKegg committed on 10/16/2017, 7:24:17 AM
Parent: b8398e992d3576abf221688bc4cd3c9a976b8834

Files changed

lib/sustained.jschanged
lib/sustained.jsView
@@ -7,8 +7,9 @@
77 // only broadcast value changes once a truthy value has stayed constant for more than timeThreshold
88
99 function Sustained (obs, timeThreshold, checkUpdateImmediately) {
1010 var outputValue = Value(obs())
11+ var lastValue = null
1112
1213 return computed(outputValue, v => v, {
1314 onListen: () => watch(obs, onChange)
1415 })
@@ -16,14 +17,18 @@
1617 function onChange (value) {
1718 if (checkUpdateImmediately && checkUpdateImmediately(value)) { // update immediately for falsy values
1819 clearTimeout()
1920 update()
20- } else if (value !== outputValue()) {
21+ } else if (value !== lastValue) {
2122 clearTimeout()
2223 setTimeout(update, timeThreshold)
24+ lastValue = value
2325 }
2426 }
2527
2628 function update () {
27- outputValue.set(obs())
29+ var value = obs()
30+ if (value !== outputValue()) {
31+ outputValue.set(value)
32+ }
2833 }
2934 }

Built with git-ssb-web