git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Commit acdbfae79726ea4f8f6b37bc223540ae5ecc093f

sustained: fix timeout bug

Matt McKegg committed on 10/28/2017, 6:45:49 AM
Parent: 91a7ee50b4fb44a1b2e9f036f697555c912d549d

Files changed

lib/sustained.jschanged
lib/sustained.jsView
@@ -8,22 +8,23 @@
88
99 function Sustained (obs, timeThreshold, checkUpdateImmediately) {
1010 var outputValue = Value(obs())
1111 var lastValue = null
12+ var timer = null
1213
1314 return computed(outputValue, v => v, {
1415 onListen: () => watch(obs, onChange)
1516 })
1617
1718 function onChange (value) {
1819 if (checkUpdateImmediately && checkUpdateImmediately(value)) { // update immediately for falsy values
19- clearTimeout()
20+ clearTimeout(timer)
2021 update()
2122 } else if (value !== lastValue) {
22- clearTimeout()
23- setTimeout(update, timeThreshold)
24- lastValue = value
23+ clearTimeout(timer)
24+ timer = setTimeout(update, timeThreshold)
2525 }
26+ lastValue = value
2627 }
2728
2829 function update () {
2930 var value = obs()

Built with git-ssb-web