Library for composing asynchronous and event-based operations in JavaScript using Observable sequences and fluent query operators
—
Operators for time-based operations including delay, throttle, debounce, and interval scheduling.
Delays the emission of elements by a specified duration.
/**
* Delays the emission of elements by the specified duration
* @param {number} dueTime - Delay duration in milliseconds
* @param {Scheduler} [scheduler] - Scheduler to use for the delay
* @returns {Observable} Observable sequence with delayed emissions
*/
observable.delay = function(dueTime, scheduler);Usage Example:
var source = Rx.Observable.range(1, 3);
var delayed = source.delay(1000);
// Emits 1, 2, 3 after 1 second delayEmits an element only after a specified duration has passed without another emission.
/**
* Emits an element only after a specified duration of silence
* @param {number} dueTime - Debounce duration in milliseconds
* @param {Scheduler} [scheduler] - Scheduler to use for timing
* @returns {Observable} Observable sequence with debounced emissions
*/
observable.debounce = function(dueTime, scheduler);Usage Example:
var source = Rx.Observable.fromEvent(textInput, 'keyup');
var debounced = source.debounce(300);
// Only emits after 300ms of no typingEmits the first element, then ignores subsequent elements for a specified duration.
/**
* Emits first element then ignores subsequent elements for specified duration
* @param {number} windowDuration - Throttle window duration in milliseconds
* @param {Scheduler} [scheduler] - Scheduler to use for timing
* @returns {Observable} Observable sequence with throttled emissions
*/
observable.throttle = function(windowDuration, scheduler);Samples the observable at specified intervals.
/**
* Samples the observable sequence at specified intervals
* @param {number|Observable} intervalOrSampler - Interval in milliseconds or sampling observable
* @param {Scheduler} [scheduler] - Scheduler to use for timing
* @returns {Observable} Observable sequence with sampled values
*/
observable.sample = function(intervalOrSampler, scheduler);Usage Example:
var source = Rx.Observable.interval(100);
var sampled = source.sample(500);
// Samples every 500ms, getting latest value from 100ms intervalApplies a timeout to the observable sequence.
/**
* Applies a timeout to the observable sequence
* @param {number} dueTime - Timeout duration in milliseconds
* @param {Observable} [other] - Observable to switch to on timeout
* @param {Scheduler} [scheduler] - Scheduler to use for timing
* @returns {Observable} Observable sequence with timeout applied
*/
observable.timeout = function(dueTime, other, scheduler);Usage Example:
var source = Rx.Observable.timer(2000);
var timeoutSource = source.timeout(1000, Rx.Observable.return('Timeout!'));
// Emits 'Timeout!' if source doesn't emit within 1 secondAttaches time interval information to each element.
/**
* Records the time interval between consecutive emissions
* @param {Scheduler} [scheduler] - Scheduler to use for timing
* @returns {Observable} Observable sequence with time interval information
*/
observable.timeInterval = function(scheduler);Usage Example:
var source = Rx.Observable.interval(1000);
var withInterval = source.timeInterval();
// Emits objects like: {value: 0, interval: 1000}Attaches timestamp information to each element.
/**
* Records the timestamp of each emission
* @param {Scheduler} [scheduler] - Scheduler to use for timing
* @returns {Observable} Observable sequence with timestamp information
*/
observable.timestamp = function(scheduler);Usage Example:
var source = Rx.Observable.range(1, 3);
var withTimestamp = source.timestamp();
// Emits objects like: {value: 1, timestamp: 1234567890}Creates an observable that emits sequential numbers at specified intervals.
/**
* Creates an observable that emits sequential numbers at specified intervals
* @param {number} period - Interval period in milliseconds
* @param {Scheduler} [scheduler] - Scheduler to use for timing
* @returns {Observable} Observable sequence of sequential numbers
*/
Rx.Observable.interval = function(period, scheduler);Usage Example:
var source = Rx.Observable.interval(1000);
// Emits: 0, 1, 2, 3, ... every 1000msCreates an observable that emits after a delay and then optionally at intervals.
/**
* Creates an observable that emits after a delay, optionally repeating
* @param {number} dueTime - Initial delay in milliseconds
* @param {number} [period] - Period for subsequent emissions in milliseconds
* @param {Scheduler} [scheduler] - Scheduler to use for timing
* @returns {Observable} Observable sequence with timer emissions
*/
Rx.Observable.timer = function(dueTime, period, scheduler);Usage Example:
var source = Rx.Observable.timer(2000, 1000);
// Waits 2s, then emits: 0, 1, 2, 3, ... every 1000msCreates windows based on time intervals.
/**
* Projects elements into zero or more windows based on timing information
* @param {number} timeSpan - Maximum time length of a window
* @param {number} [timeShift] - Interval between creation of consecutive windows
* @param {Scheduler} [scheduler] - Scheduler to use for timing
* @returns {Observable} Observable sequence of observable windows
*/
observable.windowWithTime = function(timeSpan, timeShift, scheduler);
observable.windowTime = function(timeSpan, timeShift, scheduler); // AliasBuffers elements based on time intervals.
/**
* Buffers elements into arrays based on timing information
* @param {number} timeSpan - Maximum time length of a buffer
* @param {number} [timeShift] - Interval between creation of consecutive buffers
* @param {Scheduler} [scheduler] - Scheduler to use for timing
* @returns {Observable} Observable sequence of arrays
*/
observable.bufferWithTime = function(timeSpan, timeShift, scheduler);
observable.bufferTime = function(timeSpan, timeShift, scheduler); // AliasUsage Example:
var source = Rx.Observable.interval(100);
var buffered = source.bufferWithTime(500);
// Emits arrays of values collected every 500msDelays the subscription to the source observable.
/**
* Delays the subscription to the source observable by specified duration
* @param {number} dueTime - Delay duration in milliseconds
* @param {Scheduler} [scheduler] - Scheduler to use for the delay
* @returns {Observable} Observable sequence with delayed subscription
*/
observable.delaySubscription = function(dueTime, scheduler);Time-based versions of take and skip operations.
/**
* Takes elements for the specified duration
* @param {number} duration - Duration in milliseconds to take elements
* @param {Scheduler} [scheduler] - Scheduler to use for timing
* @returns {Observable} Observable sequence taking elements for specified duration
*/
observable.takeWithTime = function(duration, scheduler);
/**
* Skips elements for the specified duration
* @param {number} duration - Duration in milliseconds to skip elements
* @param {Scheduler} [scheduler] - Scheduler to use for timing
* @returns {Observable} Observable sequence skipping elements for specified duration
*/
observable.skipWithTime = function(duration, scheduler);
/**
* Takes the last elements that occurred within the specified duration
* @param {number} duration - Duration in milliseconds
* @param {Scheduler} [scheduler] - Scheduler to use for timing
* @returns {Observable} Observable sequence of last elements within duration
*/
observable.takeLastWithTime = function(duration, scheduler);