Comparing version 0.6.0 to 0.6.1
{ | ||
"name": "most", | ||
"main": "most.js", | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"homepage": "https://github.com/cujojs/most", | ||
@@ -6,0 +6,0 @@ "authors": [ |
@@ -13,2 +13,4 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */ | ||
var delayed = promise.delay; | ||
var never = promise.never; | ||
var raceIndex = promise.raceIndex; | ||
var Yield = step.Yield; | ||
@@ -23,2 +25,4 @@ var Pair = step.Pair; | ||
exports.delayOn = delayOn; | ||
exports.debounce = debounce; | ||
exports.debounceOn = debounceOn; | ||
exports.throttle = throttle; | ||
@@ -109,2 +113,60 @@ exports.throttleOn = throttleOn; | ||
}, when(stepper, s.state)); | ||
} | ||
/** | ||
* Wait for a burst of events to subside and emit only the last event in the burst | ||
* stream: abcd----abcd---- | ||
* debounce(2, stream): -----d-------d-- | ||
* @param {Number} period events occuring more frequently than this | ||
* will be suppressed | ||
* @param {Stream} stream stream to debounce | ||
* @returns {Stream} new debounced stream | ||
*/ | ||
function debounce(period, stream) { | ||
return debounceOn(Scheduler.getDefault(), period, stream); | ||
} | ||
/** | ||
* Wait for a burst of events to subside and emit only the last event in the burst | ||
* stream: abcd----abcd---- | ||
* debounce(2, stream): -----d-------d-- | ||
* @param {Scheduler} scheduler | ||
* @param {Number} period events occuring more frequently than this | ||
* on the provided scheduler will be suppressed | ||
* @param {Stream} stream stream to debounce | ||
* @returns {Stream} new debounced stream | ||
*/ | ||
function debounceOn(scheduler, period, stream) { | ||
var stepper = stream.step; | ||
return new Stream(function(s) { | ||
return stepDebounce(scheduler, period, stepper, s); | ||
}, { timer: void 0, prev: void 0, next: void 0, state: stream.state }); | ||
} | ||
function stepDebounce(scheduler, period, step, s) { | ||
return stepEarliest(scheduler, period, step, s.timer === void 0 ? initState(step, s) : s); | ||
} | ||
function stepEarliest(scheduler, period, step, s) { | ||
return raceIndex(function(winner, index) { | ||
return index === 0 ? yieldDebounced(s) | ||
: winner.done ? winner | ||
: stepEarliest(scheduler, period, step, nextState(scheduler, period, step, winner)); | ||
}, [s.timer, s.next]); | ||
} | ||
function initState(step, s) { | ||
return { timer: never(), prev: s.prev, next: when(step, s.state), state: s.state }; | ||
} | ||
function nextState (scheduler, period, step, winner) { | ||
return { timer: delayed(period, 'timer', scheduler), prev: winner, | ||
next: when(step, winner.state), state: winner.state }; | ||
} | ||
function yieldDebounced(s) { | ||
return when(function (prev) { | ||
return new Yield(prev.value, { timer: never(), prev: void 0, | ||
next: s.next, state: prev.state }); | ||
}, s.prev); | ||
} |
18
most.js
@@ -335,2 +335,4 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */ | ||
var throttleOn = timed.throttleOn; | ||
var debounce = timed.debounce; | ||
var debounceOn = timed.debounceOn; | ||
@@ -343,2 +345,4 @@ exports.periodic = timed.periodic; | ||
exports.throttleOn = throttleOn; | ||
exports.debounce = debounce; | ||
exports.debounceOn = debounceOn; | ||
@@ -365,1 +369,15 @@ /** | ||
}; | ||
/** | ||
* Wait for a burst of events to subside and emit only the last event in the burst | ||
* stream: abcd----abcd---- | ||
* debounce(2, stream): -----d-------d-- | ||
* @param {Number} period events occuring more frequently than this | ||
* on the provided scheduler will be suppressed | ||
* @param {Scheduler=} scheduler optional scheduler | ||
* @returns {Stream} new debounced stream | ||
*/ | ||
Stream.prototype.debounce = function(period, scheduler) { | ||
return arguments.length > 1 ? debounceOn(scheduler, period, this) | ||
: debounce(period, this); | ||
}; |
{ | ||
"name": "most", | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"description": "Monadic streams", | ||
@@ -5,0 +5,0 @@ "main": "most.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
54759
1711
0