Commit 02b8eb670ca5703df29be0edc856fb4e91b20511
sustained: allow passing in timeThreshold as a function
Matt McKegg committed on 11/3/2017, 9:06:50 PMParent: 8b3e0bbdac89aa4cd743500d35bbd504bd7a49b7
Files changed
lib/sustained.js | changed |
lib/sustained.js | ||
---|---|---|
@@ -15,14 +15,15 @@ | ||
15 | 15 | onListen: () => watch(obs, onChange) |
16 | 16 | }) |
17 | 17 | |
18 | 18 | function onChange (value) { |
19 | - if (checkUpdateImmediately && checkUpdateImmediately(value)) { // update immediately for falsy values | |
19 | + if (checkUpdateImmediately && checkUpdateImmediately(value)) { | |
20 | 20 | clearTimeout(timer) |
21 | 21 | update() |
22 | 22 | } else if (value !== lastValue) { |
23 | 23 | clearTimeout(timer) |
24 | - timer = setTimeout(update, timeThreshold) | |
24 | + var delay = typeof timeThreshold === 'function' ? timeThreshold(value, outputValue()) : timeThreshold | |
25 | + timer = setTimeout(update, delay) | |
25 | 26 | } |
26 | 27 | lastValue = value |
27 | 28 | } |
28 | 29 |
Built with git-ssb-web