git ssb

10+

Matt McKegg / patchwork



Commit 02b8eb670ca5703df29be0edc856fb4e91b20511

sustained: allow passing in timeThreshold as a function

Matt McKegg committed on 11/3/2017, 9:06:50 PM
Parent: 8b3e0bbdac89aa4cd743500d35bbd504bd7a49b7

Files changed

lib/sustained.jschanged
lib/sustained.jsView
@@ -15,14 +15,15 @@
1515 onListen: () => watch(obs, onChange)
1616 })
1717
1818 function onChange (value) {
19- if (checkUpdateImmediately && checkUpdateImmediately(value)) { // update immediately for falsy values
19+ if (checkUpdateImmediately && checkUpdateImmediately(value)) {
2020 clearTimeout(timer)
2121 update()
2222 } else if (value !== lastValue) {
2323 clearTimeout(timer)
24- timer = setTimeout(update, timeThreshold)
24+ var delay = typeof timeThreshold === 'function' ? timeThreshold(value, outputValue()) : timeThreshold
25+ timer = setTimeout(update, delay)
2526 }
2627 lastValue = value
2728 }
2829

Built with git-ssb-web