Commit bc685ac97855accf26bcdf7168da942ffcdccd1a
watch-throttle: add broadcastInitial option
Matt McKegg committed on 11/19/2016, 11:43:16 AMParent: ae401384e63a7c1f60eac488db0787638deb6a7e
Files changed
watch-throttle.js | changed |
watch-throttle.js | ||
---|---|---|
@@ -1,17 +1,22 @@ | ||
1 | 1 … | var resolve = require('./resolve') |
2 | 2 … | var isObservable = require('./is-observable') |
3 | 3 … | |
4 | -module.exports = function throttledWatch (obs, minDelay, listener) { | |
4 … | +module.exports = function throttledWatch (obs, minDelay, listener, opts) { | |
5 | 5 … | var throttling = false |
6 | 6 … | var lastRefreshAt = 0 |
7 | 7 … | var lastValueAt = 0 |
8 | 8 … | var throttleTimer = null |
9 | 9 … | |
10 … | + var broadcastInitial = !opts || opts.broadcastInitial !== false | |
11 … | + | |
10 | 12 … | // default delay is 20 ms |
11 | 13 … | minDelay = minDelay || 20 |
12 | 14 … | |
13 | - listener(resolve(obs)) | |
15 … | + // run unless opts.broadcastInitial === false | |
16 … | + if (broadcastInitial) { | |
17 … | + listener(resolve(obs)) | |
18 … | + } | |
14 | 19 … | |
15 | 20 … | if (isObservable(obs)) { |
16 | 21 … | return obs(function (v) { |
17 | 22 … | if (!throttling) { |
Built with git-ssb-web