From 68c2ef76c01fcfe9fe0f727c2c87b6934a420bf5 Mon Sep 17 00:00:00 2001 From: Dan Lewi Harkestad Date: Sun, 11 Oct 2015 12:15:06 +0200 Subject: [PATCH] Fixes in rebuild-ts grunt task. rebuild-ts task would wrongly exclude typings included in the rx.lite.d.ts file. For instance would rx.time.d.ts only receive the typings not included in rx.lite.d.ts. As it was, I could only use either rx.lite.d.ts or rx.all.d.ts. However, I use a subset with rx.d.ts, rx.binding.ts and rx.time.d.ts. This fix makes it possible to do that. Instead of excluding typings included in lite, the rebuild-ts task now correctly excludes typings included in main (rx.d.ts). The original behaviour is kept if lite typings are built. I believe this is the correct behaviour, and it works nicely in my setup. I can now use a subset of the typings. I've also fixed the declare module output of rx.d.ts. It would previously add the declare module "rx" line twice, resulting in a compiler error when included in a project. --- Gruntfile.js | 8 +- ts/rx.async.d.ts | 215 ++++++++++++++++++++++++++++++ ts/rx.async.es6.d.ts | 215 ++++++++++++++++++++++++++++++ ts/rx.backpressure.d.ts | 72 ++++++++++ ts/rx.backpressure.es6.d.ts | 72 ++++++++++ ts/rx.binding.d.ts | 245 ++++++++++++++++++++++++++++++++++ ts/rx.binding.es6.d.ts | 245 ++++++++++++++++++++++++++++++++++ ts/rx.core.binding.d.ts | 245 ++++++++++++++++++++++++++++++++++ ts/rx.core.binding.es6.d.ts | 245 ++++++++++++++++++++++++++++++++++ ts/rx.d.ts | 2 +- ts/rx.es6.d.ts | 2 +- ts/rx.time.d.ts | 253 ++++++++++++++++++++++++++++++++++++ ts/rx.time.es6.d.ts | 253 ++++++++++++++++++++++++++++++++++++ 13 files changed, 2067 insertions(+), 5 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 62acf0fe1..22ef267b4 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -2619,7 +2619,9 @@ module.exports = function (grunt) { } if (!(concatKey === 'all' || concatKey === 'main' || concatKey === 'lite' || concatKey === 'core')) { - if (allLoadedFiles['lite'][tsFile] || allLoadedFiles['core'][tsFile]) { + if ((concatKey.indexOf('lite') === 0 && allLoadedFiles['lite'][tsFile]) + || (concatKey.indexOf('lite') !== 0 && allLoadedFiles['main'][tsFile]) + || allLoadedFiles['core'][tsFile]) { loadedFiles[tsFile] = true; return; } @@ -2655,7 +2657,7 @@ module.exports = function (grunt) { continue; } - if (key === 'lite' || key === 'core') { + if (key === 'lite' || key === 'main' || key === 'core') { items.unshift(key); } else { items.push(key); @@ -2717,7 +2719,7 @@ module.exports = function (grunt) { if (concatKey === 'all' || concatKey === 'main' || concatKey === 'lite' || concatKey === 'core') { outputString += '\ndeclare module "rx" { export = Rx; }\n'; } - if (dist && concatKey !== 'core') { + if (dist && concatKey !== 'core' && concatKey !== 'main') { outputString += 'declare module "'+dist+'" { export = Rx; }'; } diff --git a/ts/rx.async.d.ts b/ts/rx.async.d.ts index 57da77db6..15915ee16 100644 --- a/ts/rx.async.d.ts +++ b/ts/rx.async.d.ts @@ -69,5 +69,220 @@ declare module Rx { toAsync(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => TResult, context?: any, scheduler?: IScheduler): (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Observable; } + export interface ObservableStatic { + /** + * Converts a callback function to an observable sequence. + * + * @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence. + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next. + * @returns {Function} A function, when executed with the required parameters minus the callback, produces an Observable sequence with a single value of the arguments to the callback as an array. + */ + fromCallback(func: Function, context: any, selector: Function): (...args: any[]) => Observable; + /** + * Converts a callback function to an observable sequence. + * + * @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence. + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next. + * @returns {Function} A function, when executed with the required parameters minus the callback, produces an Observable sequence with a single value of the arguments to the callback as an array. + */ + fromCallback(func: (arg1: T1, callback: (result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1) => Observable; + /** + * Converts a callback function to an observable sequence. + * + * @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence. + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next. + * @returns {Function} A function, when executed with the required parameters minus the callback, produces an Observable sequence with a single value of the arguments to the callback as an array. + */ + fromCallback(func: (arg1: T1, arg2: T2, callback: (result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2) => Observable; + /** + * Converts a callback function to an observable sequence. + * + * @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence. + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next. + * @returns {Function} A function, when executed with the required parameters minus the callback, produces an Observable sequence with a single value of the arguments to the callback as an array. + */ + fromCallback(func: (arg1: T1, arg2: T2, arg3: T3, callback: (result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3) => Observable; + /** + * Converts a callback function to an observable sequence. + * + * @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence. + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next. + * @returns {Function} A function, when executed with the required parameters minus the callback, produces an Observable sequence with a single value of the arguments to the callback as an array. + */ + fromCallback(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Observable; + /** + * Converts a callback function to an observable sequence. + * + * @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence. + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next. + * @returns {Function} A function, when executed with the required parameters minus the callback, produces an Observable sequence with a single value of the arguments to the callback as an array. + */ + fromCallback(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Observable; + /** + * Converts a callback function to an observable sequence. + * + * @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence. + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next. + * @returns {Function} A function, when executed with the required parameters minus the callback, produces an Observable sequence with a single value of the arguments to the callback as an array. + */ + fromCallback(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, callback: (result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6) => Observable; + /** + * Converts a callback function to an observable sequence. + * + * @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence. + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next. + * @returns {Function} A function, when executed with the required parameters minus the callback, produces an Observable sequence with a single value of the arguments to the callback as an array. + */ + fromCallback(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, callback: (result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7) => Observable; + /** + * Converts a callback function to an observable sequence. + * + * @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence. + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next. + * @returns {Function} A function, when executed with the required parameters minus the callback, produces an Observable sequence with a single value of the arguments to the callback as an array. + */ + fromCallback(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, arg8: T8, callback: (result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, arg8: T8) => Observable; + /** + * Converts a callback function to an observable sequence. + * + * @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence. + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next. + * @returns {Function} A function, when executed with the required parameters minus the callback, produces an Observable sequence with a single value of the arguments to the callback as an array. + */ + fromCallback(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, arg8: T8, arg9: T9, callback: (result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, arg8: T8, arg9: T9) => Observable; + } + + export interface ObservableStatic { + /** + * Converts a Node.js callback style function to an observable sequence. This must be in function (err, ...) format. + * @param {Function} func The function to call + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback minus the error to produce a single item to yield on next. + * @returns {Function} An async function which when applied, returns an observable sequence with the callback arguments as an array. + */ + fromNodeCallback(func: Function, context?: any, selector?: Function): (...args: any[]) => Observable; + /** + * Converts a Node.js callback style function to an observable sequence. This must be in function (err, ...) format. + * @param {Function} func The function to call + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback minus the error to produce a single item to yield on next. + * @returns {Function} An async function which when applied, returns an observable sequence with the callback arguments as an array. + */ + fromNodeCallback(func: (arg1: T1, callback: (err: any, result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1) => Observable; + /** + * Converts a Node.js callback style function to an observable sequence. This must be in function (err, ...) format. + * @param {Function} func The function to call + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback minus the error to produce a single item to yield on next. + * @returns {Function} An async function which when applied, returns an observable sequence with the callback arguments as an array. + */ + fromNodeCallback(func: (arg1: T1, arg2: T2, callback: (err: any, result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2) => Observable; + /** + * Converts a Node.js callback style function to an observable sequence. This must be in function (err, ...) format. + * @param {Function} func The function to call + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback minus the error to produce a single item to yield on next. + * @returns {Function} An async function which when applied, returns an observable sequence with the callback arguments as an array. + */ + fromNodeCallback(func: (arg1: T1, arg2: T2, arg3: T3, callback: (err: any, result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3) => Observable; + /** + * Converts a Node.js callback style function to an observable sequence. This must be in function (err, ...) format. + * @param {Function} func The function to call + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback minus the error to produce a single item to yield on next. + * @returns {Function} An async function which when applied, returns an observable sequence with the callback arguments as an array. + */ + fromNodeCallback(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err: any, result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Observable; + /** + * Converts a Node.js callback style function to an observable sequence. This must be in function (err, ...) format. + * @param {Function} func The function to call + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback minus the error to produce a single item to yield on next. + * @returns {Function} An async function which when applied, returns an observable sequence with the callback arguments as an array. + */ + fromNodeCallback(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err: any, result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Observable; + /** + * Converts a Node.js callback style function to an observable sequence. This must be in function (err, ...) format. + * @param {Function} func The function to call + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback minus the error to produce a single item to yield on next. + * @returns {Function} An async function which when applied, returns an observable sequence with the callback arguments as an array. + */ + fromNodeCallback(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, callback: (err: any, result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6) => Observable; + /** + * Converts a Node.js callback style function to an observable sequence. This must be in function (err, ...) format. + * @param {Function} func The function to call + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback minus the error to produce a single item to yield on next. + * @returns {Function} An async function which when applied, returns an observable sequence with the callback arguments as an array. + */ + fromNodeCallback(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, callback: (err: any, result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7) => Observable; + /** + * Converts a Node.js callback style function to an observable sequence. This must be in function (err, ...) format. + * @param {Function} func The function to call + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback minus the error to produce a single item to yield on next. + * @returns {Function} An async function which when applied, returns an observable sequence with the callback arguments as an array. + */ + fromNodeCallback(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, arg8: T8, callback: (err: any, result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, arg8: T8) => Observable; + /** + * Converts a Node.js callback style function to an observable sequence. This must be in function (err, ...) format. + * @param {Function} func The function to call + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback minus the error to produce a single item to yield on next. + * @returns {Function} An async function which when applied, returns an observable sequence with the callback arguments as an array. + */ + fromNodeCallback(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, arg8: T8, arg9: T9, callback: (err: any, result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, arg8: T8, arg9: T9) => Observable; + } + + export interface ObservableStatic { + /** + * Creates an observable sequence by adding an event listener to the matching DOMElement or each item in the NodeList. + * @param {Object} element The DOMElement or NodeList to attach a listener. + * @param {String} eventName The event name to attach the observable sequence. + * @param {Function} [selector] A selector which takes the arguments from the event handler to produce a single item to yield on next. + * @returns {Observable} An observable sequence of events from the specified element and the specified event. + */ + fromEvent(element: EventTarget, eventName: string, selector?: (arguments: any[]) => T): Observable; + /** + * Creates an observable sequence by adding an event listener to the matching DOMElement or each item in the NodeList. + * @param {Object} element The DOMElement or NodeList to attach a listener. + * @param {String} eventName The event name to attach the observable sequence. + * @param {Function} [selector] A selector which takes the arguments from the event handler to produce a single item to yield on next. + * @returns {Observable} An observable sequence of events from the specified element and the specified event. + */ + fromEvent(element: { on: (name: string, cb: (e: any) => any) => void; off: (name: string, cb: (e: any) => any) => void }, eventName: string, selector?: (arguments: any[]) => T): Observable; + } + + export interface ObservableStatic { + /** + * Creates an observable sequence from an event emitter via an addHandler/removeHandler pair. + * @param {Function} addHandler The function to add a handler to the emitter. + * @param {Function} [removeHandler] The optional function to remove a handler from an emitter. + * @param {Function} [selector] A selector which takes the arguments from the event handler to produce a single item to yield on next. + * @returns {Observable} An observable sequence which wraps an event from an event emitter + */ + fromEventPattern(addHandler: (handler: Function) => void, removeHandler: (handler: Function) => void, selector?: (arguments: any[]) => T): Observable; + } + + export interface ObservableStatic { + /** + * Invokes the asynchronous function, surfacing the result through an observable sequence. + * @param {Function} functionAsync Asynchronous function which returns a Promise to run. + * @returns {Observable} An observable sequence exposing the function's result value, or an exception. + */ + startAsync(functionAsync: () => IPromise): Observable; + } + } declare module "rx.async" { export = Rx; } diff --git a/ts/rx.async.es6.d.ts b/ts/rx.async.es6.d.ts index 57da77db6..15915ee16 100644 --- a/ts/rx.async.es6.d.ts +++ b/ts/rx.async.es6.d.ts @@ -69,5 +69,220 @@ declare module Rx { toAsync(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => TResult, context?: any, scheduler?: IScheduler): (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Observable; } + export interface ObservableStatic { + /** + * Converts a callback function to an observable sequence. + * + * @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence. + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next. + * @returns {Function} A function, when executed with the required parameters minus the callback, produces an Observable sequence with a single value of the arguments to the callback as an array. + */ + fromCallback(func: Function, context: any, selector: Function): (...args: any[]) => Observable; + /** + * Converts a callback function to an observable sequence. + * + * @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence. + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next. + * @returns {Function} A function, when executed with the required parameters minus the callback, produces an Observable sequence with a single value of the arguments to the callback as an array. + */ + fromCallback(func: (arg1: T1, callback: (result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1) => Observable; + /** + * Converts a callback function to an observable sequence. + * + * @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence. + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next. + * @returns {Function} A function, when executed with the required parameters minus the callback, produces an Observable sequence with a single value of the arguments to the callback as an array. + */ + fromCallback(func: (arg1: T1, arg2: T2, callback: (result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2) => Observable; + /** + * Converts a callback function to an observable sequence. + * + * @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence. + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next. + * @returns {Function} A function, when executed with the required parameters minus the callback, produces an Observable sequence with a single value of the arguments to the callback as an array. + */ + fromCallback(func: (arg1: T1, arg2: T2, arg3: T3, callback: (result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3) => Observable; + /** + * Converts a callback function to an observable sequence. + * + * @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence. + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next. + * @returns {Function} A function, when executed with the required parameters minus the callback, produces an Observable sequence with a single value of the arguments to the callback as an array. + */ + fromCallback(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Observable; + /** + * Converts a callback function to an observable sequence. + * + * @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence. + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next. + * @returns {Function} A function, when executed with the required parameters minus the callback, produces an Observable sequence with a single value of the arguments to the callback as an array. + */ + fromCallback(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Observable; + /** + * Converts a callback function to an observable sequence. + * + * @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence. + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next. + * @returns {Function} A function, when executed with the required parameters minus the callback, produces an Observable sequence with a single value of the arguments to the callback as an array. + */ + fromCallback(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, callback: (result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6) => Observable; + /** + * Converts a callback function to an observable sequence. + * + * @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence. + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next. + * @returns {Function} A function, when executed with the required parameters minus the callback, produces an Observable sequence with a single value of the arguments to the callback as an array. + */ + fromCallback(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, callback: (result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7) => Observable; + /** + * Converts a callback function to an observable sequence. + * + * @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence. + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next. + * @returns {Function} A function, when executed with the required parameters minus the callback, produces an Observable sequence with a single value of the arguments to the callback as an array. + */ + fromCallback(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, arg8: T8, callback: (result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, arg8: T8) => Observable; + /** + * Converts a callback function to an observable sequence. + * + * @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence. + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next. + * @returns {Function} A function, when executed with the required parameters minus the callback, produces an Observable sequence with a single value of the arguments to the callback as an array. + */ + fromCallback(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, arg8: T8, arg9: T9, callback: (result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, arg8: T8, arg9: T9) => Observable; + } + + export interface ObservableStatic { + /** + * Converts a Node.js callback style function to an observable sequence. This must be in function (err, ...) format. + * @param {Function} func The function to call + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback minus the error to produce a single item to yield on next. + * @returns {Function} An async function which when applied, returns an observable sequence with the callback arguments as an array. + */ + fromNodeCallback(func: Function, context?: any, selector?: Function): (...args: any[]) => Observable; + /** + * Converts a Node.js callback style function to an observable sequence. This must be in function (err, ...) format. + * @param {Function} func The function to call + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback minus the error to produce a single item to yield on next. + * @returns {Function} An async function which when applied, returns an observable sequence with the callback arguments as an array. + */ + fromNodeCallback(func: (arg1: T1, callback: (err: any, result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1) => Observable; + /** + * Converts a Node.js callback style function to an observable sequence. This must be in function (err, ...) format. + * @param {Function} func The function to call + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback minus the error to produce a single item to yield on next. + * @returns {Function} An async function which when applied, returns an observable sequence with the callback arguments as an array. + */ + fromNodeCallback(func: (arg1: T1, arg2: T2, callback: (err: any, result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2) => Observable; + /** + * Converts a Node.js callback style function to an observable sequence. This must be in function (err, ...) format. + * @param {Function} func The function to call + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback minus the error to produce a single item to yield on next. + * @returns {Function} An async function which when applied, returns an observable sequence with the callback arguments as an array. + */ + fromNodeCallback(func: (arg1: T1, arg2: T2, arg3: T3, callback: (err: any, result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3) => Observable; + /** + * Converts a Node.js callback style function to an observable sequence. This must be in function (err, ...) format. + * @param {Function} func The function to call + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback minus the error to produce a single item to yield on next. + * @returns {Function} An async function which when applied, returns an observable sequence with the callback arguments as an array. + */ + fromNodeCallback(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err: any, result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Observable; + /** + * Converts a Node.js callback style function to an observable sequence. This must be in function (err, ...) format. + * @param {Function} func The function to call + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback minus the error to produce a single item to yield on next. + * @returns {Function} An async function which when applied, returns an observable sequence with the callback arguments as an array. + */ + fromNodeCallback(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err: any, result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Observable; + /** + * Converts a Node.js callback style function to an observable sequence. This must be in function (err, ...) format. + * @param {Function} func The function to call + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback minus the error to produce a single item to yield on next. + * @returns {Function} An async function which when applied, returns an observable sequence with the callback arguments as an array. + */ + fromNodeCallback(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, callback: (err: any, result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6) => Observable; + /** + * Converts a Node.js callback style function to an observable sequence. This must be in function (err, ...) format. + * @param {Function} func The function to call + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback minus the error to produce a single item to yield on next. + * @returns {Function} An async function which when applied, returns an observable sequence with the callback arguments as an array. + */ + fromNodeCallback(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, callback: (err: any, result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7) => Observable; + /** + * Converts a Node.js callback style function to an observable sequence. This must be in function (err, ...) format. + * @param {Function} func The function to call + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback minus the error to produce a single item to yield on next. + * @returns {Function} An async function which when applied, returns an observable sequence with the callback arguments as an array. + */ + fromNodeCallback(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, arg8: T8, callback: (err: any, result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, arg8: T8) => Observable; + /** + * Converts a Node.js callback style function to an observable sequence. This must be in function (err, ...) format. + * @param {Function} func The function to call + * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined. + * @param {Function} [selector] A selector which takes the arguments from the callback minus the error to produce a single item to yield on next. + * @returns {Function} An async function which when applied, returns an observable sequence with the callback arguments as an array. + */ + fromNodeCallback(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, arg8: T8, arg9: T9, callback: (err: any, result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, arg8: T8, arg9: T9) => Observable; + } + + export interface ObservableStatic { + /** + * Creates an observable sequence by adding an event listener to the matching DOMElement or each item in the NodeList. + * @param {Object} element The DOMElement or NodeList to attach a listener. + * @param {String} eventName The event name to attach the observable sequence. + * @param {Function} [selector] A selector which takes the arguments from the event handler to produce a single item to yield on next. + * @returns {Observable} An observable sequence of events from the specified element and the specified event. + */ + fromEvent(element: EventTarget, eventName: string, selector?: (arguments: any[]) => T): Observable; + /** + * Creates an observable sequence by adding an event listener to the matching DOMElement or each item in the NodeList. + * @param {Object} element The DOMElement or NodeList to attach a listener. + * @param {String} eventName The event name to attach the observable sequence. + * @param {Function} [selector] A selector which takes the arguments from the event handler to produce a single item to yield on next. + * @returns {Observable} An observable sequence of events from the specified element and the specified event. + */ + fromEvent(element: { on: (name: string, cb: (e: any) => any) => void; off: (name: string, cb: (e: any) => any) => void }, eventName: string, selector?: (arguments: any[]) => T): Observable; + } + + export interface ObservableStatic { + /** + * Creates an observable sequence from an event emitter via an addHandler/removeHandler pair. + * @param {Function} addHandler The function to add a handler to the emitter. + * @param {Function} [removeHandler] The optional function to remove a handler from an emitter. + * @param {Function} [selector] A selector which takes the arguments from the event handler to produce a single item to yield on next. + * @returns {Observable} An observable sequence which wraps an event from an event emitter + */ + fromEventPattern(addHandler: (handler: Function) => void, removeHandler: (handler: Function) => void, selector?: (arguments: any[]) => T): Observable; + } + + export interface ObservableStatic { + /** + * Invokes the asynchronous function, surfacing the result through an observable sequence. + * @param {Function} functionAsync Asynchronous function which returns a Promise to run. + * @returns {Observable} An observable sequence exposing the function's result value, or an exception. + */ + startAsync(functionAsync: () => IPromise): Observable; + } + } declare module "rx.async" { export = Rx; } diff --git a/ts/rx.backpressure.d.ts b/ts/rx.backpressure.d.ts index 9b26f0cab..3229a949b 100644 --- a/ts/rx.backpressure.d.ts +++ b/ts/rx.backpressure.d.ts @@ -1,5 +1,67 @@ declare module Rx { + /** + * Used to pause and resume streams. + */ + export interface Pauser { + /** + * Pauses the underlying sequence. + */ + pause(): void; + + /** + * Resumes the underlying sequence. + */ + resume(): void; + } + + export interface Observable { + /** + * Pauses the underlying observable sequence based upon the observable sequence which yields true/false. + * @example + * var pauser = new Rx.Subject(); + * var source = Rx.Observable.interval(100).pausable(pauser); + * @param {Observable} pauser The observable sequence used to pause the underlying sequence. + * @returns {Observable} The observable sequence which is paused based upon the pauser. + */ + pausable(pauser?: Observable): PausableObservable; + } + + export interface PausableObservable extends Observable { + pause(): void; + resume(): void; + } + + export interface Observable { + /** + * Pauses the underlying observable sequence based upon the observable sequence which yields true/false, + * and yields the values that were buffered while paused. + * @example + * var pauser = new Rx.Subject(); + * var source = Rx.Observable.interval(100).pausableBuffered(pauser); + * @param {Observable} pauser The observable sequence used to pause the underlying sequence. + * @returns {Observable} The observable sequence which is paused based upon the pauser. + */ + pausableBuffered(pauser?: Observable): PausableObservable; + } + + export interface Observable { + /** + * Attaches a controller to the observable sequence with the ability to queue. + * @example + * var source = Rx.Observable.interval(100).controlled(); + * source.request(3); // Reads 3 values + * @param {bool} enableQueue truthy value to determine if values should be queued pending the next request + * @param {Scheduler} scheduler determines how the requests will be scheduled + * @returns {Observable} The observable sequence which only propagates values on request. + */ + controlled(enableQueue?: boolean, scheduler?: IScheduler): ControlledObservable; + } + + export interface ControlledObservable extends Observable { + request(numberOfItems?: number): IDisposable; + } + export interface ControlledObservable { /** * Attaches a stop and wait observable to the current observable. @@ -17,5 +79,15 @@ declare module Rx { windowed(windowSize: number): Observable; } + export interface Observable { + /** + * Pipes the existing Observable sequence into a Node.js Stream. + * @param {Stream} dest The destination Node.js stream. + * @returns {Stream} The destination stream. + */ + pipe(dest: TDest): TDest; + // TODO: Add link to node.d.ts some where + } + } declare module "rx.backpressure" { export = Rx; } diff --git a/ts/rx.backpressure.es6.d.ts b/ts/rx.backpressure.es6.d.ts index 9b26f0cab..3229a949b 100644 --- a/ts/rx.backpressure.es6.d.ts +++ b/ts/rx.backpressure.es6.d.ts @@ -1,5 +1,67 @@ declare module Rx { + /** + * Used to pause and resume streams. + */ + export interface Pauser { + /** + * Pauses the underlying sequence. + */ + pause(): void; + + /** + * Resumes the underlying sequence. + */ + resume(): void; + } + + export interface Observable { + /** + * Pauses the underlying observable sequence based upon the observable sequence which yields true/false. + * @example + * var pauser = new Rx.Subject(); + * var source = Rx.Observable.interval(100).pausable(pauser); + * @param {Observable} pauser The observable sequence used to pause the underlying sequence. + * @returns {Observable} The observable sequence which is paused based upon the pauser. + */ + pausable(pauser?: Observable): PausableObservable; + } + + export interface PausableObservable extends Observable { + pause(): void; + resume(): void; + } + + export interface Observable { + /** + * Pauses the underlying observable sequence based upon the observable sequence which yields true/false, + * and yields the values that were buffered while paused. + * @example + * var pauser = new Rx.Subject(); + * var source = Rx.Observable.interval(100).pausableBuffered(pauser); + * @param {Observable} pauser The observable sequence used to pause the underlying sequence. + * @returns {Observable} The observable sequence which is paused based upon the pauser. + */ + pausableBuffered(pauser?: Observable): PausableObservable; + } + + export interface Observable { + /** + * Attaches a controller to the observable sequence with the ability to queue. + * @example + * var source = Rx.Observable.interval(100).controlled(); + * source.request(3); // Reads 3 values + * @param {bool} enableQueue truthy value to determine if values should be queued pending the next request + * @param {Scheduler} scheduler determines how the requests will be scheduled + * @returns {Observable} The observable sequence which only propagates values on request. + */ + controlled(enableQueue?: boolean, scheduler?: IScheduler): ControlledObservable; + } + + export interface ControlledObservable extends Observable { + request(numberOfItems?: number): IDisposable; + } + export interface ControlledObservable { /** * Attaches a stop and wait observable to the current observable. @@ -17,5 +79,15 @@ declare module Rx { windowed(windowSize: number): Observable; } + export interface Observable { + /** + * Pipes the existing Observable sequence into a Node.js Stream. + * @param {Stream} dest The destination Node.js stream. + * @returns {Stream} The destination stream. + */ + pipe(dest: TDest): TDest; + // TODO: Add link to node.d.ts some where + } + } declare module "rx.backpressure" { export = Rx; } diff --git a/ts/rx.binding.d.ts b/ts/rx.binding.d.ts index 90a809aab..fe3efecb5 100644 --- a/ts/rx.binding.d.ts +++ b/ts/rx.binding.d.ts @@ -1,5 +1,250 @@ declare module Rx { + export interface ConnectableObservable extends Observable { + connect(): IDisposable; + refCount(): Observable; + } + + export interface Observable { + /** + * Multicasts the source sequence notifications through an instantiated subject into all uses of the sequence within a selector function. Each + * subscription to the resulting sequence causes a separate multicast invocation, exposing the sequence resulting from the selector function's + * invocation. For specializations with fixed subject types, see Publish, PublishLast, and Replay. + * + * @example + * 1 - res = source.multicast(observable); + * 2 - res = source.multicast(function () { return new Subject(); }, function (x) { return x; }); + * + * @param {Function|Subject} subjectOrSubjectSelector + * Factory function to create an intermediate subject through which the source sequence's elements will be multicast to the selector function. + * Or: + * Subject to push source elements into. + * + * @param {Function} [selector] Optional selector function which can use the multicasted source sequence subject to the policies enforced by the created subject. Specified only if | (() => ISubject)): ConnectableObservable; + /** + * Multicasts the source sequence notifications through an instantiated subject into all uses of the sequence within a selector function. Each + * subscription to the resulting sequence causes a separate multicast invocation, exposing the sequence resulting from the selector function's + * invocation. For specializations with fixed subject types, see Publish, PublishLast, and Replay. + * + * @example + * 1 - res = source.multicast(observable); + * 2 - res = source.multicast(function () { return new Subject(); }, function (x) { return x; }); + * + * @param {Function|Subject} subjectOrSubjectSelector + * Factory function to create an intermediate subject through which the source sequence's elements will be multicast to the selector function. + * Or: + * Subject to push source elements into. + * + * @param {Function} [selector] Optional selector function which can use the multicasted source sequence subject to the policies enforced by the created subject. Specified only if (subjectSelector: ISubject | (() => ISubject), selector: (source: ConnectableObservable) => Observable): Observable; + } + + export interface Observable { + /** + * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence. + * This operator is a specialization of Multicast using a regular Subject. + * + * @example + * var resres = source.publish(); + * var res = source.publish(function (x) { return x; }); + * + * @param {Function} [selector] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all notifications of the source from the time of the subscription on. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. + */ + publish(): ConnectableObservable; + /** + * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence. + * This operator is a specialization of Multicast using a regular Subject. + * + * @example + * var resres = source.publish(); + * var res = source.publish(function (x) { return x; }); + * + * @param {Function} [selector] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all notifications of the source from the time of the subscription on. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. + */ + publish(selector: (source: ConnectableObservable) => Observable): Observable; + } + + export interface Observable { + /** + * Returns an observable sequence that shares a single subscription to the underlying sequence. + * This operator is a specialization of publish which creates a subscription when the number of observers goes from zero to one, then shares that subscription with all subsequent observers until the number of observers returns to zero, at which point the subscription is disposed. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence. + */ + share(): Observable; + } + + export interface Observable { + /** + * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence containing only the last notification. + * This operator is a specialization of Multicast using a AsyncSubject. + * + * @example + * var res = source.publishLast(); + * var res = source.publishLast(function (x) { return x; }); + * + * @param selector [Optional] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will only receive the last notification of the source. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. + */ + publishLast(): ConnectableObservable; + /** + * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence containing only the last notification. + * This operator is a specialization of Multicast using a AsyncSubject. + * + * @example + * var res = source.publishLast(); + * var res = source.publishLast(function (x) { return x; }); + * + * @param selector [Optional] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will only receive the last notification of the source. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. + */ + publishLast(selector: (source: ConnectableObservable) => Observable): Observable; + } + + export interface Observable { + /** + * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence and starts with initialValue. + * This operator is a specialization of Multicast using a BehaviorSubject. + * + * @example + * var res = source.publishValue(42); + * var res = source.publishValue(function (x) { return x.select(function (y) { return y * y; }) }, 42); + * + * @param {Function} [selector] Optional selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive immediately receive the initial value, followed by all notifications of the source from the time of the subscription on. + * @param {Mixed} initialValue Initial value received by observers upon subscription. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. + */ + publishValue(initialValue: T): ConnectableObservable; + /** + * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence and starts with initialValue. + * This operator is a specialization of Multicast using a BehaviorSubject. + * + * @example + * var res = source.publishValue(42); + * var res = source.publishValue(function (x) { return x.select(function (y) { return y * y; }) }, 42); + * + * @param {Function} [selector] Optional selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive immediately receive the initial value, followed by all notifications of the source from the time of the subscription on. + * @param {Mixed} initialValue Initial value received by observers upon subscription. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. + */ + publishValue(selector: (source: ConnectableObservable) => Observable, initialValue: T): Observable; + } + + export interface Observable { + /** + * Returns an observable sequence that shares a single subscription to the underlying sequence and starts with an initialValue. + * This operator is a specialization of publishValue which creates a subscription when the number of observers goes from zero to one, then shares that subscription with all subsequent observers until the number of observers returns to zero, at which point the subscription is disposed. + * @param {Mixed} initialValue Initial value received by observers upon subscription. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence. + */ + shareValue(initialValue: T): Observable; + } + + export interface Observable { + /** + * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length for the replay buffer. + * This operator is a specialization of Multicast using a ReplaySubject. + * + * @example + * var res = source.replay(null, 3); + * var res = source.replay(null, 3, 500); + * var res = source.replay(null, 3, 500, scheduler); + * var res = source.replay(function (x) { return x.take(6).repeat(); }, 3, 500, scheduler); + * + * @param selector [Optional] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all the notifications of the source subject to the specified replay buffer trimming policy. + * @param bufferSize [Optional] Maximum element count of the replay buffer. + * @param windowSize [Optional] Maximum time length of the replay buffer. + * @param scheduler [Optional] Scheduler where connected observers within the selector function will be invoked on. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. + */ + replay(selector?: void, bufferSize?: number, window?: number, scheduler?: IScheduler): ConnectableObservable; // hack to catch first omitted parameter + /** + * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length for the replay buffer. + * This operator is a specialization of Multicast using a ReplaySubject. + * + * @example + * var res = source.replay(null, 3); + * var res = source.replay(null, 3, 500); + * var res = source.replay(null, 3, 500, scheduler); + * var res = source.replay(function (x) { return x.take(6).repeat(); }, 3, 500, scheduler); + * + * @param selector [Optional] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all the notifications of the source subject to the specified replay buffer trimming policy. + * @param bufferSize [Optional] Maximum element count of the replay buffer. + * @param windowSize [Optional] Maximum time length of the replay buffer. + * @param scheduler [Optional] Scheduler where connected observers within the selector function will be invoked on. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. + */ + replay(selector: (source: ConnectableObservable) => Observable, bufferSize?: number, window?: number, scheduler?: IScheduler): Observable; + } + + export interface Observable { + /** + * Returns an observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length for the replay buffer. + * This operator is a specialization of replay which creates a subscription when the number of observers goes from zero to one, then shares that subscription with all subsequent observers until the number of observers returns to zero, at which point the subscription is disposed. + * + * @example + * var res = source.shareReplay(3); + * var res = source.shareReplay(3, 500); + * var res = source.shareReplay(3, 500, scheduler); + * + + * @param bufferSize [Optional] Maximum element count of the replay buffer. + * @param window [Optional] Maximum time length of the replay buffer. + * @param scheduler [Optional] Scheduler where connected observers within the selector function will be invoked on. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence. + */ + shareReplay(bufferSize?: number, window?: number, scheduler?: IScheduler): Observable; + } + + export interface BehaviorSubject extends Subject { + /** + * Gets the current value or throws an exception. + * Value is frozen after onCompleted is called. + * After onError is called always throws the specified exception. + * An exception is always thrown after dispose is called. + * @returns {Mixed} The initial value passed to the constructor until onNext is called; after which, the last value passed to onNext. + */ + getValue(): T; + } + + interface BehaviorSubjectStatic { + /** + * Initializes a new instance of the BehaviorSubject class which creates a subject that caches its last value and starts with the specified value. + * @param {Mixed} value Initial value sent to observers when no other value has been received by the subject yet. + */ + new (initialValue: T): BehaviorSubject; + } + + /** + * Represents a value that changes over time. + * Observers can subscribe to the subject to receive the last (or initial) value and all subsequent notifications. + */ + export var BehaviorSubject: BehaviorSubjectStatic; + + export interface ReplaySubject extends Subject { } + + interface ReplaySubjectStatic { + /** + * Initializes a new instance of the ReplaySubject class with the specified buffer size, window size and scheduler. + * @param {Number} [bufferSize] Maximum element count of the replay buffer. + * @param {Number} [windowSize] Maximum time length of the replay buffer. + * @param {Scheduler} [scheduler] Scheduler the observers are invoked on. + */ + new (bufferSize?: number, window?: number, scheduler?: IScheduler): ReplaySubject; + } + + /** + * Represents an object that is both an observable sequence as well as an observer. + * Each notification is broadcasted to all subscribed and future observers, subject to buffer trimming policies. + */ + export var ReplaySubject: ReplaySubjectStatic; + export interface Observable { /** * Returns an observable sequence that shares a single subscription to the underlying sequence. This observable sequence diff --git a/ts/rx.binding.es6.d.ts b/ts/rx.binding.es6.d.ts index 90a809aab..fe3efecb5 100644 --- a/ts/rx.binding.es6.d.ts +++ b/ts/rx.binding.es6.d.ts @@ -1,5 +1,250 @@ declare module Rx { + export interface ConnectableObservable extends Observable { + connect(): IDisposable; + refCount(): Observable; + } + + export interface Observable { + /** + * Multicasts the source sequence notifications through an instantiated subject into all uses of the sequence within a selector function. Each + * subscription to the resulting sequence causes a separate multicast invocation, exposing the sequence resulting from the selector function's + * invocation. For specializations with fixed subject types, see Publish, PublishLast, and Replay. + * + * @example + * 1 - res = source.multicast(observable); + * 2 - res = source.multicast(function () { return new Subject(); }, function (x) { return x; }); + * + * @param {Function|Subject} subjectOrSubjectSelector + * Factory function to create an intermediate subject through which the source sequence's elements will be multicast to the selector function. + * Or: + * Subject to push source elements into. + * + * @param {Function} [selector] Optional selector function which can use the multicasted source sequence subject to the policies enforced by the created subject. Specified only if | (() => ISubject)): ConnectableObservable; + /** + * Multicasts the source sequence notifications through an instantiated subject into all uses of the sequence within a selector function. Each + * subscription to the resulting sequence causes a separate multicast invocation, exposing the sequence resulting from the selector function's + * invocation. For specializations with fixed subject types, see Publish, PublishLast, and Replay. + * + * @example + * 1 - res = source.multicast(observable); + * 2 - res = source.multicast(function () { return new Subject(); }, function (x) { return x; }); + * + * @param {Function|Subject} subjectOrSubjectSelector + * Factory function to create an intermediate subject through which the source sequence's elements will be multicast to the selector function. + * Or: + * Subject to push source elements into. + * + * @param {Function} [selector] Optional selector function which can use the multicasted source sequence subject to the policies enforced by the created subject. Specified only if (subjectSelector: ISubject | (() => ISubject), selector: (source: ConnectableObservable) => Observable): Observable; + } + + export interface Observable { + /** + * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence. + * This operator is a specialization of Multicast using a regular Subject. + * + * @example + * var resres = source.publish(); + * var res = source.publish(function (x) { return x; }); + * + * @param {Function} [selector] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all notifications of the source from the time of the subscription on. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. + */ + publish(): ConnectableObservable; + /** + * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence. + * This operator is a specialization of Multicast using a regular Subject. + * + * @example + * var resres = source.publish(); + * var res = source.publish(function (x) { return x; }); + * + * @param {Function} [selector] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all notifications of the source from the time of the subscription on. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. + */ + publish(selector: (source: ConnectableObservable) => Observable): Observable; + } + + export interface Observable { + /** + * Returns an observable sequence that shares a single subscription to the underlying sequence. + * This operator is a specialization of publish which creates a subscription when the number of observers goes from zero to one, then shares that subscription with all subsequent observers until the number of observers returns to zero, at which point the subscription is disposed. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence. + */ + share(): Observable; + } + + export interface Observable { + /** + * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence containing only the last notification. + * This operator is a specialization of Multicast using a AsyncSubject. + * + * @example + * var res = source.publishLast(); + * var res = source.publishLast(function (x) { return x; }); + * + * @param selector [Optional] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will only receive the last notification of the source. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. + */ + publishLast(): ConnectableObservable; + /** + * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence containing only the last notification. + * This operator is a specialization of Multicast using a AsyncSubject. + * + * @example + * var res = source.publishLast(); + * var res = source.publishLast(function (x) { return x; }); + * + * @param selector [Optional] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will only receive the last notification of the source. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. + */ + publishLast(selector: (source: ConnectableObservable) => Observable): Observable; + } + + export interface Observable { + /** + * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence and starts with initialValue. + * This operator is a specialization of Multicast using a BehaviorSubject. + * + * @example + * var res = source.publishValue(42); + * var res = source.publishValue(function (x) { return x.select(function (y) { return y * y; }) }, 42); + * + * @param {Function} [selector] Optional selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive immediately receive the initial value, followed by all notifications of the source from the time of the subscription on. + * @param {Mixed} initialValue Initial value received by observers upon subscription. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. + */ + publishValue(initialValue: T): ConnectableObservable; + /** + * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence and starts with initialValue. + * This operator is a specialization of Multicast using a BehaviorSubject. + * + * @example + * var res = source.publishValue(42); + * var res = source.publishValue(function (x) { return x.select(function (y) { return y * y; }) }, 42); + * + * @param {Function} [selector] Optional selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive immediately receive the initial value, followed by all notifications of the source from the time of the subscription on. + * @param {Mixed} initialValue Initial value received by observers upon subscription. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. + */ + publishValue(selector: (source: ConnectableObservable) => Observable, initialValue: T): Observable; + } + + export interface Observable { + /** + * Returns an observable sequence that shares a single subscription to the underlying sequence and starts with an initialValue. + * This operator is a specialization of publishValue which creates a subscription when the number of observers goes from zero to one, then shares that subscription with all subsequent observers until the number of observers returns to zero, at which point the subscription is disposed. + * @param {Mixed} initialValue Initial value received by observers upon subscription. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence. + */ + shareValue(initialValue: T): Observable; + } + + export interface Observable { + /** + * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length for the replay buffer. + * This operator is a specialization of Multicast using a ReplaySubject. + * + * @example + * var res = source.replay(null, 3); + * var res = source.replay(null, 3, 500); + * var res = source.replay(null, 3, 500, scheduler); + * var res = source.replay(function (x) { return x.take(6).repeat(); }, 3, 500, scheduler); + * + * @param selector [Optional] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all the notifications of the source subject to the specified replay buffer trimming policy. + * @param bufferSize [Optional] Maximum element count of the replay buffer. + * @param windowSize [Optional] Maximum time length of the replay buffer. + * @param scheduler [Optional] Scheduler where connected observers within the selector function will be invoked on. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. + */ + replay(selector?: void, bufferSize?: number, window?: number, scheduler?: IScheduler): ConnectableObservable; // hack to catch first omitted parameter + /** + * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length for the replay buffer. + * This operator is a specialization of Multicast using a ReplaySubject. + * + * @example + * var res = source.replay(null, 3); + * var res = source.replay(null, 3, 500); + * var res = source.replay(null, 3, 500, scheduler); + * var res = source.replay(function (x) { return x.take(6).repeat(); }, 3, 500, scheduler); + * + * @param selector [Optional] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all the notifications of the source subject to the specified replay buffer trimming policy. + * @param bufferSize [Optional] Maximum element count of the replay buffer. + * @param windowSize [Optional] Maximum time length of the replay buffer. + * @param scheduler [Optional] Scheduler where connected observers within the selector function will be invoked on. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. + */ + replay(selector: (source: ConnectableObservable) => Observable, bufferSize?: number, window?: number, scheduler?: IScheduler): Observable; + } + + export interface Observable { + /** + * Returns an observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length for the replay buffer. + * This operator is a specialization of replay which creates a subscription when the number of observers goes from zero to one, then shares that subscription with all subsequent observers until the number of observers returns to zero, at which point the subscription is disposed. + * + * @example + * var res = source.shareReplay(3); + * var res = source.shareReplay(3, 500); + * var res = source.shareReplay(3, 500, scheduler); + * + + * @param bufferSize [Optional] Maximum element count of the replay buffer. + * @param window [Optional] Maximum time length of the replay buffer. + * @param scheduler [Optional] Scheduler where connected observers within the selector function will be invoked on. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence. + */ + shareReplay(bufferSize?: number, window?: number, scheduler?: IScheduler): Observable; + } + + export interface BehaviorSubject extends Subject { + /** + * Gets the current value or throws an exception. + * Value is frozen after onCompleted is called. + * After onError is called always throws the specified exception. + * An exception is always thrown after dispose is called. + * @returns {Mixed} The initial value passed to the constructor until onNext is called; after which, the last value passed to onNext. + */ + getValue(): T; + } + + interface BehaviorSubjectStatic { + /** + * Initializes a new instance of the BehaviorSubject class which creates a subject that caches its last value and starts with the specified value. + * @param {Mixed} value Initial value sent to observers when no other value has been received by the subject yet. + */ + new (initialValue: T): BehaviorSubject; + } + + /** + * Represents a value that changes over time. + * Observers can subscribe to the subject to receive the last (or initial) value and all subsequent notifications. + */ + export var BehaviorSubject: BehaviorSubjectStatic; + + export interface ReplaySubject extends Subject { } + + interface ReplaySubjectStatic { + /** + * Initializes a new instance of the ReplaySubject class with the specified buffer size, window size and scheduler. + * @param {Number} [bufferSize] Maximum element count of the replay buffer. + * @param {Number} [windowSize] Maximum time length of the replay buffer. + * @param {Scheduler} [scheduler] Scheduler the observers are invoked on. + */ + new (bufferSize?: number, window?: number, scheduler?: IScheduler): ReplaySubject; + } + + /** + * Represents an object that is both an observable sequence as well as an observer. + * Each notification is broadcasted to all subscribed and future observers, subject to buffer trimming policies. + */ + export var ReplaySubject: ReplaySubjectStatic; + export interface Observable { /** * Returns an observable sequence that shares a single subscription to the underlying sequence. This observable sequence diff --git a/ts/rx.core.binding.d.ts b/ts/rx.core.binding.d.ts index 7dd9da04c..146b8e499 100644 --- a/ts/rx.core.binding.d.ts +++ b/ts/rx.core.binding.d.ts @@ -1,4 +1,249 @@ declare module Rx { + export interface ConnectableObservable extends Observable { + connect(): IDisposable; + refCount(): Observable; + } + + export interface Observable { + /** + * Multicasts the source sequence notifications through an instantiated subject into all uses of the sequence within a selector function. Each + * subscription to the resulting sequence causes a separate multicast invocation, exposing the sequence resulting from the selector function's + * invocation. For specializations with fixed subject types, see Publish, PublishLast, and Replay. + * + * @example + * 1 - res = source.multicast(observable); + * 2 - res = source.multicast(function () { return new Subject(); }, function (x) { return x; }); + * + * @param {Function|Subject} subjectOrSubjectSelector + * Factory function to create an intermediate subject through which the source sequence's elements will be multicast to the selector function. + * Or: + * Subject to push source elements into. + * + * @param {Function} [selector] Optional selector function which can use the multicasted source sequence subject to the policies enforced by the created subject. Specified only if | (() => ISubject)): ConnectableObservable; + /** + * Multicasts the source sequence notifications through an instantiated subject into all uses of the sequence within a selector function. Each + * subscription to the resulting sequence causes a separate multicast invocation, exposing the sequence resulting from the selector function's + * invocation. For specializations with fixed subject types, see Publish, PublishLast, and Replay. + * + * @example + * 1 - res = source.multicast(observable); + * 2 - res = source.multicast(function () { return new Subject(); }, function (x) { return x; }); + * + * @param {Function|Subject} subjectOrSubjectSelector + * Factory function to create an intermediate subject through which the source sequence's elements will be multicast to the selector function. + * Or: + * Subject to push source elements into. + * + * @param {Function} [selector] Optional selector function which can use the multicasted source sequence subject to the policies enforced by the created subject. Specified only if (subjectSelector: ISubject | (() => ISubject), selector: (source: ConnectableObservable) => Observable): Observable; + } + + export interface Observable { + /** + * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence. + * This operator is a specialization of Multicast using a regular Subject. + * + * @example + * var resres = source.publish(); + * var res = source.publish(function (x) { return x; }); + * + * @param {Function} [selector] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all notifications of the source from the time of the subscription on. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. + */ + publish(): ConnectableObservable; + /** + * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence. + * This operator is a specialization of Multicast using a regular Subject. + * + * @example + * var resres = source.publish(); + * var res = source.publish(function (x) { return x; }); + * + * @param {Function} [selector] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all notifications of the source from the time of the subscription on. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. + */ + publish(selector: (source: ConnectableObservable) => Observable): Observable; + } + + export interface Observable { + /** + * Returns an observable sequence that shares a single subscription to the underlying sequence. + * This operator is a specialization of publish which creates a subscription when the number of observers goes from zero to one, then shares that subscription with all subsequent observers until the number of observers returns to zero, at which point the subscription is disposed. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence. + */ + share(): Observable; + } + + export interface Observable { + /** + * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence containing only the last notification. + * This operator is a specialization of Multicast using a AsyncSubject. + * + * @example + * var res = source.publishLast(); + * var res = source.publishLast(function (x) { return x; }); + * + * @param selector [Optional] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will only receive the last notification of the source. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. + */ + publishLast(): ConnectableObservable; + /** + * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence containing only the last notification. + * This operator is a specialization of Multicast using a AsyncSubject. + * + * @example + * var res = source.publishLast(); + * var res = source.publishLast(function (x) { return x; }); + * + * @param selector [Optional] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will only receive the last notification of the source. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. + */ + publishLast(selector: (source: ConnectableObservable) => Observable): Observable; + } + + export interface Observable { + /** + * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence and starts with initialValue. + * This operator is a specialization of Multicast using a BehaviorSubject. + * + * @example + * var res = source.publishValue(42); + * var res = source.publishValue(function (x) { return x.select(function (y) { return y * y; }) }, 42); + * + * @param {Function} [selector] Optional selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive immediately receive the initial value, followed by all notifications of the source from the time of the subscription on. + * @param {Mixed} initialValue Initial value received by observers upon subscription. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. + */ + publishValue(initialValue: T): ConnectableObservable; + /** + * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence and starts with initialValue. + * This operator is a specialization of Multicast using a BehaviorSubject. + * + * @example + * var res = source.publishValue(42); + * var res = source.publishValue(function (x) { return x.select(function (y) { return y * y; }) }, 42); + * + * @param {Function} [selector] Optional selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive immediately receive the initial value, followed by all notifications of the source from the time of the subscription on. + * @param {Mixed} initialValue Initial value received by observers upon subscription. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. + */ + publishValue(selector: (source: ConnectableObservable) => Observable, initialValue: T): Observable; + } + + export interface Observable { + /** + * Returns an observable sequence that shares a single subscription to the underlying sequence and starts with an initialValue. + * This operator is a specialization of publishValue which creates a subscription when the number of observers goes from zero to one, then shares that subscription with all subsequent observers until the number of observers returns to zero, at which point the subscription is disposed. + * @param {Mixed} initialValue Initial value received by observers upon subscription. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence. + */ + shareValue(initialValue: T): Observable; + } + + export interface Observable { + /** + * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length for the replay buffer. + * This operator is a specialization of Multicast using a ReplaySubject. + * + * @example + * var res = source.replay(null, 3); + * var res = source.replay(null, 3, 500); + * var res = source.replay(null, 3, 500, scheduler); + * var res = source.replay(function (x) { return x.take(6).repeat(); }, 3, 500, scheduler); + * + * @param selector [Optional] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all the notifications of the source subject to the specified replay buffer trimming policy. + * @param bufferSize [Optional] Maximum element count of the replay buffer. + * @param windowSize [Optional] Maximum time length of the replay buffer. + * @param scheduler [Optional] Scheduler where connected observers within the selector function will be invoked on. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. + */ + replay(selector?: void, bufferSize?: number, window?: number, scheduler?: IScheduler): ConnectableObservable; // hack to catch first omitted parameter + /** + * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length for the replay buffer. + * This operator is a specialization of Multicast using a ReplaySubject. + * + * @example + * var res = source.replay(null, 3); + * var res = source.replay(null, 3, 500); + * var res = source.replay(null, 3, 500, scheduler); + * var res = source.replay(function (x) { return x.take(6).repeat(); }, 3, 500, scheduler); + * + * @param selector [Optional] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all the notifications of the source subject to the specified replay buffer trimming policy. + * @param bufferSize [Optional] Maximum element count of the replay buffer. + * @param windowSize [Optional] Maximum time length of the replay buffer. + * @param scheduler [Optional] Scheduler where connected observers within the selector function will be invoked on. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. + */ + replay(selector: (source: ConnectableObservable) => Observable, bufferSize?: number, window?: number, scheduler?: IScheduler): Observable; + } + + export interface Observable { + /** + * Returns an observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length for the replay buffer. + * This operator is a specialization of replay which creates a subscription when the number of observers goes from zero to one, then shares that subscription with all subsequent observers until the number of observers returns to zero, at which point the subscription is disposed. + * + * @example + * var res = source.shareReplay(3); + * var res = source.shareReplay(3, 500); + * var res = source.shareReplay(3, 500, scheduler); + * + + * @param bufferSize [Optional] Maximum element count of the replay buffer. + * @param window [Optional] Maximum time length of the replay buffer. + * @param scheduler [Optional] Scheduler where connected observers within the selector function will be invoked on. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence. + */ + shareReplay(bufferSize?: number, window?: number, scheduler?: IScheduler): Observable; + } + + export interface BehaviorSubject extends Subject { + /** + * Gets the current value or throws an exception. + * Value is frozen after onCompleted is called. + * After onError is called always throws the specified exception. + * An exception is always thrown after dispose is called. + * @returns {Mixed} The initial value passed to the constructor until onNext is called; after which, the last value passed to onNext. + */ + getValue(): T; + } + + interface BehaviorSubjectStatic { + /** + * Initializes a new instance of the BehaviorSubject class which creates a subject that caches its last value and starts with the specified value. + * @param {Mixed} value Initial value sent to observers when no other value has been received by the subject yet. + */ + new (initialValue: T): BehaviorSubject; + } + + /** + * Represents a value that changes over time. + * Observers can subscribe to the subject to receive the last (or initial) value and all subsequent notifications. + */ + export var BehaviorSubject: BehaviorSubjectStatic; + + export interface ReplaySubject extends Subject { } + + interface ReplaySubjectStatic { + /** + * Initializes a new instance of the ReplaySubject class with the specified buffer size, window size and scheduler. + * @param {Number} [bufferSize] Maximum element count of the replay buffer. + * @param {Number} [windowSize] Maximum time length of the replay buffer. + * @param {Scheduler} [scheduler] Scheduler the observers are invoked on. + */ + new (bufferSize?: number, window?: number, scheduler?: IScheduler): ReplaySubject; + } + + /** + * Represents an object that is both an observable sequence as well as an observer. + * Each notification is broadcasted to all subscribed and future observers, subject to buffer trimming policies. + */ + export var ReplaySubject: ReplaySubjectStatic; + } declare module "rx.core.binding" { export = Rx; } diff --git a/ts/rx.core.binding.es6.d.ts b/ts/rx.core.binding.es6.d.ts index 7dd9da04c..146b8e499 100644 --- a/ts/rx.core.binding.es6.d.ts +++ b/ts/rx.core.binding.es6.d.ts @@ -1,4 +1,249 @@ declare module Rx { + export interface ConnectableObservable extends Observable { + connect(): IDisposable; + refCount(): Observable; + } + + export interface Observable { + /** + * Multicasts the source sequence notifications through an instantiated subject into all uses of the sequence within a selector function. Each + * subscription to the resulting sequence causes a separate multicast invocation, exposing the sequence resulting from the selector function's + * invocation. For specializations with fixed subject types, see Publish, PublishLast, and Replay. + * + * @example + * 1 - res = source.multicast(observable); + * 2 - res = source.multicast(function () { return new Subject(); }, function (x) { return x; }); + * + * @param {Function|Subject} subjectOrSubjectSelector + * Factory function to create an intermediate subject through which the source sequence's elements will be multicast to the selector function. + * Or: + * Subject to push source elements into. + * + * @param {Function} [selector] Optional selector function which can use the multicasted source sequence subject to the policies enforced by the created subject. Specified only if | (() => ISubject)): ConnectableObservable; + /** + * Multicasts the source sequence notifications through an instantiated subject into all uses of the sequence within a selector function. Each + * subscription to the resulting sequence causes a separate multicast invocation, exposing the sequence resulting from the selector function's + * invocation. For specializations with fixed subject types, see Publish, PublishLast, and Replay. + * + * @example + * 1 - res = source.multicast(observable); + * 2 - res = source.multicast(function () { return new Subject(); }, function (x) { return x; }); + * + * @param {Function|Subject} subjectOrSubjectSelector + * Factory function to create an intermediate subject through which the source sequence's elements will be multicast to the selector function. + * Or: + * Subject to push source elements into. + * + * @param {Function} [selector] Optional selector function which can use the multicasted source sequence subject to the policies enforced by the created subject. Specified only if (subjectSelector: ISubject | (() => ISubject), selector: (source: ConnectableObservable) => Observable): Observable; + } + + export interface Observable { + /** + * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence. + * This operator is a specialization of Multicast using a regular Subject. + * + * @example + * var resres = source.publish(); + * var res = source.publish(function (x) { return x; }); + * + * @param {Function} [selector] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all notifications of the source from the time of the subscription on. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. + */ + publish(): ConnectableObservable; + /** + * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence. + * This operator is a specialization of Multicast using a regular Subject. + * + * @example + * var resres = source.publish(); + * var res = source.publish(function (x) { return x; }); + * + * @param {Function} [selector] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all notifications of the source from the time of the subscription on. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. + */ + publish(selector: (source: ConnectableObservable) => Observable): Observable; + } + + export interface Observable { + /** + * Returns an observable sequence that shares a single subscription to the underlying sequence. + * This operator is a specialization of publish which creates a subscription when the number of observers goes from zero to one, then shares that subscription with all subsequent observers until the number of observers returns to zero, at which point the subscription is disposed. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence. + */ + share(): Observable; + } + + export interface Observable { + /** + * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence containing only the last notification. + * This operator is a specialization of Multicast using a AsyncSubject. + * + * @example + * var res = source.publishLast(); + * var res = source.publishLast(function (x) { return x; }); + * + * @param selector [Optional] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will only receive the last notification of the source. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. + */ + publishLast(): ConnectableObservable; + /** + * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence containing only the last notification. + * This operator is a specialization of Multicast using a AsyncSubject. + * + * @example + * var res = source.publishLast(); + * var res = source.publishLast(function (x) { return x; }); + * + * @param selector [Optional] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will only receive the last notification of the source. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. + */ + publishLast(selector: (source: ConnectableObservable) => Observable): Observable; + } + + export interface Observable { + /** + * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence and starts with initialValue. + * This operator is a specialization of Multicast using a BehaviorSubject. + * + * @example + * var res = source.publishValue(42); + * var res = source.publishValue(function (x) { return x.select(function (y) { return y * y; }) }, 42); + * + * @param {Function} [selector] Optional selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive immediately receive the initial value, followed by all notifications of the source from the time of the subscription on. + * @param {Mixed} initialValue Initial value received by observers upon subscription. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. + */ + publishValue(initialValue: T): ConnectableObservable; + /** + * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence and starts with initialValue. + * This operator is a specialization of Multicast using a BehaviorSubject. + * + * @example + * var res = source.publishValue(42); + * var res = source.publishValue(function (x) { return x.select(function (y) { return y * y; }) }, 42); + * + * @param {Function} [selector] Optional selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive immediately receive the initial value, followed by all notifications of the source from the time of the subscription on. + * @param {Mixed} initialValue Initial value received by observers upon subscription. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. + */ + publishValue(selector: (source: ConnectableObservable) => Observable, initialValue: T): Observable; + } + + export interface Observable { + /** + * Returns an observable sequence that shares a single subscription to the underlying sequence and starts with an initialValue. + * This operator is a specialization of publishValue which creates a subscription when the number of observers goes from zero to one, then shares that subscription with all subsequent observers until the number of observers returns to zero, at which point the subscription is disposed. + * @param {Mixed} initialValue Initial value received by observers upon subscription. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence. + */ + shareValue(initialValue: T): Observable; + } + + export interface Observable { + /** + * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length for the replay buffer. + * This operator is a specialization of Multicast using a ReplaySubject. + * + * @example + * var res = source.replay(null, 3); + * var res = source.replay(null, 3, 500); + * var res = source.replay(null, 3, 500, scheduler); + * var res = source.replay(function (x) { return x.take(6).repeat(); }, 3, 500, scheduler); + * + * @param selector [Optional] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all the notifications of the source subject to the specified replay buffer trimming policy. + * @param bufferSize [Optional] Maximum element count of the replay buffer. + * @param windowSize [Optional] Maximum time length of the replay buffer. + * @param scheduler [Optional] Scheduler where connected observers within the selector function will be invoked on. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. + */ + replay(selector?: void, bufferSize?: number, window?: number, scheduler?: IScheduler): ConnectableObservable; // hack to catch first omitted parameter + /** + * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length for the replay buffer. + * This operator is a specialization of Multicast using a ReplaySubject. + * + * @example + * var res = source.replay(null, 3); + * var res = source.replay(null, 3, 500); + * var res = source.replay(null, 3, 500, scheduler); + * var res = source.replay(function (x) { return x.take(6).repeat(); }, 3, 500, scheduler); + * + * @param selector [Optional] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all the notifications of the source subject to the specified replay buffer trimming policy. + * @param bufferSize [Optional] Maximum element count of the replay buffer. + * @param windowSize [Optional] Maximum time length of the replay buffer. + * @param scheduler [Optional] Scheduler where connected observers within the selector function will be invoked on. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. + */ + replay(selector: (source: ConnectableObservable) => Observable, bufferSize?: number, window?: number, scheduler?: IScheduler): Observable; + } + + export interface Observable { + /** + * Returns an observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length for the replay buffer. + * This operator is a specialization of replay which creates a subscription when the number of observers goes from zero to one, then shares that subscription with all subsequent observers until the number of observers returns to zero, at which point the subscription is disposed. + * + * @example + * var res = source.shareReplay(3); + * var res = source.shareReplay(3, 500); + * var res = source.shareReplay(3, 500, scheduler); + * + + * @param bufferSize [Optional] Maximum element count of the replay buffer. + * @param window [Optional] Maximum time length of the replay buffer. + * @param scheduler [Optional] Scheduler where connected observers within the selector function will be invoked on. + * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence. + */ + shareReplay(bufferSize?: number, window?: number, scheduler?: IScheduler): Observable; + } + + export interface BehaviorSubject extends Subject { + /** + * Gets the current value or throws an exception. + * Value is frozen after onCompleted is called. + * After onError is called always throws the specified exception. + * An exception is always thrown after dispose is called. + * @returns {Mixed} The initial value passed to the constructor until onNext is called; after which, the last value passed to onNext. + */ + getValue(): T; + } + + interface BehaviorSubjectStatic { + /** + * Initializes a new instance of the BehaviorSubject class which creates a subject that caches its last value and starts with the specified value. + * @param {Mixed} value Initial value sent to observers when no other value has been received by the subject yet. + */ + new (initialValue: T): BehaviorSubject; + } + + /** + * Represents a value that changes over time. + * Observers can subscribe to the subject to receive the last (or initial) value and all subsequent notifications. + */ + export var BehaviorSubject: BehaviorSubjectStatic; + + export interface ReplaySubject extends Subject { } + + interface ReplaySubjectStatic { + /** + * Initializes a new instance of the ReplaySubject class with the specified buffer size, window size and scheduler. + * @param {Number} [bufferSize] Maximum element count of the replay buffer. + * @param {Number} [windowSize] Maximum time length of the replay buffer. + * @param {Scheduler} [scheduler] Scheduler the observers are invoked on. + */ + new (bufferSize?: number, window?: number, scheduler?: IScheduler): ReplaySubject; + } + + /** + * Represents an object that is both an observable sequence as well as an observer. + * Each notification is broadcasted to all subscribed and future observers, subject to buffer trimming policies. + */ + export var ReplaySubject: ReplaySubjectStatic; + } declare module "rx.core.binding" { export = Rx; } diff --git a/ts/rx.d.ts b/ts/rx.d.ts index 4d842a874..bddd017e4 100644 --- a/ts/rx.d.ts +++ b/ts/rx.d.ts @@ -2422,4 +2422,4 @@ declare module Rx { } declare module "rx" { export = Rx; } -declare module "rx" { export = Rx; } + diff --git a/ts/rx.es6.d.ts b/ts/rx.es6.d.ts index ea1b399c0..aa84ecd3d 100644 --- a/ts/rx.es6.d.ts +++ b/ts/rx.es6.d.ts @@ -2419,4 +2419,4 @@ declare module Rx { } declare module "rx" { export = Rx; } -declare module "rx" { export = Rx; } + diff --git a/ts/rx.time.d.ts b/ts/rx.time.d.ts index eb7c290d8..e6305c946 100644 --- a/ts/rx.time.d.ts +++ b/ts/rx.time.d.ts @@ -1,5 +1,115 @@ declare module Rx { + export interface ObservableStatic { + /** + * Returns an observable sequence that produces a value after each period. + * + * @example + * 1 - res = Rx.Observable.interval(1000); + * 2 - res = Rx.Observable.interval(1000, Rx.Scheduler.timeout); + * + * @param {Number} period Period for producing the values in the resulting sequence (specified as an integer denoting milliseconds). + * @param {Scheduler} [scheduler] Scheduler to run the timer on. If not specified, Rx.Scheduler.timeout is used. + * @returns {Observable} An observable sequence that produces a value after each period. + */ + interval(period: number, scheduler?: IScheduler): Observable; + } + + export interface ObservableStatic { + /** + * Returns an observable sequence that produces a value after dueTime has elapsed and then after each period. + * @param {Number} dueTime Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) at which to produce the first value. + * @param {Mixed} [periodOrScheduler] Period to produce subsequent values (specified as an integer denoting milliseconds), or the scheduler to run the timer on. If not specified, the resulting timer is not recurring. + * @param {Scheduler} [scheduler] Scheduler to run the timer on. If not specified, the timeout scheduler is used. + * @returns {Observable} An observable sequence that produces a value after due time has elapsed and then each period. + */ + timer(dueTime: number, period: number, scheduler?: IScheduler): Observable; + /** + * Returns an observable sequence that produces a value after dueTime has elapsed and then after each period. + * @param {Number} dueTime Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) at which to produce the first value. + * @param {Mixed} [periodOrScheduler] Period to produce subsequent values (specified as an integer denoting milliseconds), or the scheduler to run the timer on. If not specified, the resulting timer is not recurring. + * @param {Scheduler} [scheduler] Scheduler to run the timer on. If not specified, the timeout scheduler is used. + * @returns {Observable} An observable sequence that produces a value after due time has elapsed and then each period. + */ + timer(dueTime: number, scheduler?: IScheduler): Observable; + } + + export interface Observable { + /** + * Time shifts the observable sequence by dueTime. The relative time intervals between the values are preserved. + * + * @example + * 1 - res = Rx.Observable.delay(new Date()); + * 2 - res = Rx.Observable.delay(new Date(), Rx.Scheduler.timeout); + * + * 3 - res = Rx.Observable.delay(5000); + * 4 - res = Rx.Observable.delay(5000, 1000, Rx.Scheduler.timeout); + * @memberOf Observable# + * @param {Number} dueTime Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) by which to shift the observable sequence. + * @param {Scheduler} [scheduler] Scheduler to run the delay timers on. If not specified, the timeout scheduler is used. + * @returns {Observable} Time-shifted sequence. + */ + delay(dueTime: Date, scheduler?: IScheduler): Observable; + /** + * Time shifts the observable sequence by dueTime. The relative time intervals between the values are preserved. + * + * @example + * 1 - res = Rx.Observable.delay(new Date()); + * 2 - res = Rx.Observable.delay(new Date(), Rx.Scheduler.timeout); + * + * 3 - res = Rx.Observable.delay(5000); + * 4 - res = Rx.Observable.delay(5000, 1000, Rx.Scheduler.timeout); + * @memberOf Observable# + * @param {Number} dueTime Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) by which to shift the observable sequence. + * @param {Scheduler} [scheduler] Scheduler to run the delay timers on. If not specified, the timeout scheduler is used. + * @returns {Observable} Time-shifted sequence. + */ + delay(dueTime: number, scheduler?: IScheduler): Observable; + + /** + * Time shifts the observable sequence based on a subscription delay and a delay selector function for each element. + * + * @example + * 1 - res = source.delayWithSelector(function (x) { return Rx.Scheduler.timer(5000); }); // with selector only + * 1 - res = source.delayWithSelector(Rx.Observable.timer(2000), function (x) { return Rx.Observable.timer(x); }); // with delay and selector + * + * @param {Observable} [subscriptionDelay] Sequence indicating the delay for the subscription to the source. + * @param {Function} delayDurationSelector Selector function to retrieve a sequence indicating the delay for each given element. + * @returns {Observable} Time-shifted sequence. + */ + delay(delayDurationSelector: (item: T) => ObservableOrPromise): Observable; + + /** + * Time shifts the observable sequence based on a subscription delay and a delay selector function for each element. + * + * @example + * 1 - res = source.delayWithSelector(function (x) { return Rx.Scheduler.timer(5000); }); // with selector only + * 1 - res = source.delayWithSelector(Rx.Observable.timer(2000), function (x) { return Rx.Observable.timer(x); }); // with delay and selector + * + * @param {Observable} [subscriptionDelay] Sequence indicating the delay for the subscription to the source. + * @param {Function} delayDurationSelector Selector function to retrieve a sequence indicating the delay for each given element. + * @returns {Observable} Time-shifted sequence. + */ + delay(subscriptionDelay: Observable, delayDurationSelector: (item: T) => ObservableOrPromise): Observable; + } + + export interface Observable { + /** + * Ignores values from an observable sequence which are followed by another value before dueTime. + * @param {Number} dueTime Duration of the debounce period for each value (specified as an integer denoting milliseconds). + * @param {Scheduler} [scheduler] Scheduler to run the debounce timers on. If not specified, the timeout scheduler is used. + * @returns {Observable} The debounced sequence. + */ + debounce(dueTime: number, scheduler?: IScheduler): Observable; + + /** + * Ignores values from an observable sequence which are followed by another value within a computed throttle duration. + * @param {Function} durationSelector Selector function to retrieve a sequence indicating the throttle duration for each given element. + * @returns {Observable} The debounced sequence. + */ + debounce(debounceDurationSelector: (item: T) => ObservableOrPromise): Observable; + } + export interface Observable { /** * Projects each element of an observable sequence into zero or more windows which are produced based on timing information. @@ -79,6 +189,139 @@ declare module Rx { timeInterval(scheduler?: IScheduler): Observable>; } + export interface Timestamp { + value: T; + timestamp: number; + } + + export interface Observable { + /** + * Records the timestamp for each value in an observable sequence. + * + * @example + * 1 - res = source.timestamp(); // produces { value: x, timestamp: ts } + * 2 - res = source.timestamp(Rx.Scheduler.default); + * + * @param {Scheduler} [scheduler] Scheduler used to compute timestamps. If not specified, the default scheduler is used. + * @returns {Observable} An observable sequence with timestamp information on values. + */ + timestamp(scheduler?: IScheduler): Observable>; + } + + export interface Observable { + /** + * Samples the observable sequence at each interval. + * + * @example + * 1 - res = source.sample(sampleObservable); // Sampler tick sequence + * 2 - res = source.sample(5000); // 5 seconds + * 2 - res = source.sample(5000, Rx.Scheduler.timeout); // 5 seconds + * + * @param {Mixed} intervalOrSampler Interval at which to sample (specified as an integer denoting milliseconds) or Sampler Observable. + * @param {Scheduler} [scheduler] Scheduler to run the sampling timer on. If not specified, the timeout scheduler is used. + * @returns {Observable} Sampled observable sequence. + */ + sample(intervalOrSampler: number, scheduler?: IScheduler): Observable; + /** + * Samples the observable sequence at each interval. + * + * @example + * 1 - res = source.sample(sampleObservable); // Sampler tick sequence + * 2 - res = source.sample(5000); // 5 seconds + * 2 - res = source.sample(5000, Rx.Scheduler.timeout); // 5 seconds + * + * @param {Mixed} intervalOrSampler Interval at which to sample (specified as an integer denoting milliseconds) or Sampler Observable. + * @param {Scheduler} [scheduler] Scheduler to run the sampling timer on. If not specified, the timeout scheduler is used. + * @returns {Observable} Sampled observable sequence. + */ + sample(sampler: Observable, scheduler?: IScheduler): Observable; + /** + * Samples the observable sequence at each interval. + * + * @example + * 1 - res = source.sample(sampleObservable); // Sampler tick sequence + * 2 - res = source.sample(5000); // 5 seconds + * 2 - res = source.sample(5000, Rx.Scheduler.timeout); // 5 seconds + * + * @param {Mixed} intervalOrSampler Interval at which to sample (specified as an integer denoting milliseconds) or Sampler Observable. + * @param {Scheduler} [scheduler] Scheduler to run the sampling timer on. If not specified, the timeout scheduler is used. + * @returns {Observable} Sampled observable sequence. + */ + throttleLatest(interval: number, scheduler?: IScheduler): Observable; + /** + * Samples the observable sequence at each interval. + * + * @example + * 1 - res = source.sample(sampleObservable); // Sampler tick sequence + * 2 - res = source.sample(5000); // 5 seconds + * 2 - res = source.sample(5000, Rx.Scheduler.timeout); // 5 seconds + * + * @param {Mixed} intervalOrSampler Interval at which to sample (specified as an integer denoting milliseconds) or Sampler Observable. + * @param {Scheduler} [scheduler] Scheduler to run the sampling timer on. If not specified, the timeout scheduler is used. + * @returns {Observable} Sampled observable sequence. + */ + throttleLatest(sampler: Observable, scheduler?: IScheduler): Observable; + } + + export interface Observable { + /** + * Returns the source observable sequence or the other observable sequence if dueTime elapses. + * @param {Number} dueTime Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) when a timeout occurs. + * @param {Scheduler} [scheduler] Scheduler to run the timeout timers on. If not specified, the timeout scheduler is used. + * @returns {Observable} The source sequence switching to the other sequence in case of a timeout. + */ + timeout(dueTime: Date, scheduler?: IScheduler): Observable; + + /** + * Returns the source observable sequence or the other observable sequence if dueTime elapses. + * @param {Number} dueTime Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) when a timeout occurs. + * @param {Observable} [other] Sequence to return in case of a timeout. If not specified, a timeout error throwing sequence will be used. + * @param {Scheduler} [scheduler] Scheduler to run the timeout timers on. If not specified, the timeout scheduler is used. + * @returns {Observable} The source sequence switching to the other sequence in case of a timeout. + */ + timeout(dueTime: Date, other?: Observable, scheduler?: IScheduler): Observable; + /** + * Returns the source observable sequence or the other observable sequence if dueTime elapses. + * @param {Number} dueTime Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) when a timeout occurs. + * @param {Observable} [other] Sequence to return in case of a timeout. If not specified, a timeout error throwing sequence will be used. + * @param {Scheduler} [scheduler] Scheduler to run the timeout timers on. If not specified, the timeout scheduler is used. + * @returns {Observable} The source sequence switching to the other sequence in case of a timeout. + */ + timeout(dueTime: number, scheduler?: IScheduler): Observable; + /** + * Returns the source observable sequence or the other observable sequence if dueTime elapses. + * @param {Number} dueTime Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) when a timeout occurs. + * @param {Observable} [other] Sequence to return in case of a timeout. If not specified, a timeout error throwing sequence will be used. + * @param {Scheduler} [scheduler] Scheduler to run the timeout timers on. If not specified, the timeout scheduler is used. + * @returns {Observable} The source sequence switching to the other sequence in case of a timeout. + */ + timeout(dueTime: number, other?: Observable, scheduler?: IScheduler): Observable; + + /** + * Returns the source observable sequence, switching to the other observable sequence if a timeout is signaled. + * @param {Function} timeoutDurationSelector Selector to retrieve an observable sequence that represents the timeout between the current element and the next element. + * @returns {Observable} The source sequence switching to the other sequence in case of a timeout. + */ + timeout(timeoutdurationSelector: (item: T) => Observable): Observable; + + /** + * Returns the source observable sequence, switching to the other observable sequence if a timeout is signaled. + * @param {Function} timeoutDurationSelector Selector to retrieve an observable sequence that represents the timeout between the current element and the next element. + * @param {Observable} other Sequence to return in case of a timeout. If not provided, this is set to Observable.throwException(). + * @returns {Observable} The source sequence switching to the other sequence in case of a timeout. + */ + timeout(timeoutdurationSelector: (item: T) => Observable, other: Observable): Observable; + + /** + * Returns the source observable sequence, switching to the other observable sequence if a timeout is signaled. + * @param {Observable} [firstTimeout] Observable sequence that represents the timeout for the first element. If not provided, this defaults to Observable.never(). + * @param {Function} timeoutDurationSelector Selector to retrieve an observable sequence that represents the timeout between the current element and the next element. + * @param {Observable} [other] Sequence to return in case of a timeout. If not provided, this is set to Observable.throwException(). + * @returns {Observable} The source sequence switching to the other sequence in case of a timeout. + */ + timeout(firstTimeout: Observable, timeoutdurationSelector: (item: T) => Observable, other?: Observable): Observable; + } + export interface ObservableStatic { /** * Generates an observable sequence by iterating a state from an initial state until the condition fails. @@ -279,5 +522,15 @@ declare module Rx { takeUntilWithTime(duration: number, scheduler?: IScheduler): Observable; } + export interface Observable { + /** + * Returns an Observable that emits only the first item emitted by the source Observable during sequential time windows of a specified duration. + * @param {Number} windowDuration time to wait before emitting another item after emitting the last item + * @param {Scheduler} [scheduler] the Scheduler to use internally to manage the timers that handle timeout for each item. If not provided, defaults to Scheduler.timeout. + * @returns {Observable} An Observable that performs the throttle operation. + */ + throttle(windowDuration: number, scheduler?: IScheduler): Observable; + } + } declare module "rx.time" { export = Rx; } diff --git a/ts/rx.time.es6.d.ts b/ts/rx.time.es6.d.ts index eb7c290d8..e6305c946 100644 --- a/ts/rx.time.es6.d.ts +++ b/ts/rx.time.es6.d.ts @@ -1,5 +1,115 @@ declare module Rx { + export interface ObservableStatic { + /** + * Returns an observable sequence that produces a value after each period. + * + * @example + * 1 - res = Rx.Observable.interval(1000); + * 2 - res = Rx.Observable.interval(1000, Rx.Scheduler.timeout); + * + * @param {Number} period Period for producing the values in the resulting sequence (specified as an integer denoting milliseconds). + * @param {Scheduler} [scheduler] Scheduler to run the timer on. If not specified, Rx.Scheduler.timeout is used. + * @returns {Observable} An observable sequence that produces a value after each period. + */ + interval(period: number, scheduler?: IScheduler): Observable; + } + + export interface ObservableStatic { + /** + * Returns an observable sequence that produces a value after dueTime has elapsed and then after each period. + * @param {Number} dueTime Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) at which to produce the first value. + * @param {Mixed} [periodOrScheduler] Period to produce subsequent values (specified as an integer denoting milliseconds), or the scheduler to run the timer on. If not specified, the resulting timer is not recurring. + * @param {Scheduler} [scheduler] Scheduler to run the timer on. If not specified, the timeout scheduler is used. + * @returns {Observable} An observable sequence that produces a value after due time has elapsed and then each period. + */ + timer(dueTime: number, period: number, scheduler?: IScheduler): Observable; + /** + * Returns an observable sequence that produces a value after dueTime has elapsed and then after each period. + * @param {Number} dueTime Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) at which to produce the first value. + * @param {Mixed} [periodOrScheduler] Period to produce subsequent values (specified as an integer denoting milliseconds), or the scheduler to run the timer on. If not specified, the resulting timer is not recurring. + * @param {Scheduler} [scheduler] Scheduler to run the timer on. If not specified, the timeout scheduler is used. + * @returns {Observable} An observable sequence that produces a value after due time has elapsed and then each period. + */ + timer(dueTime: number, scheduler?: IScheduler): Observable; + } + + export interface Observable { + /** + * Time shifts the observable sequence by dueTime. The relative time intervals between the values are preserved. + * + * @example + * 1 - res = Rx.Observable.delay(new Date()); + * 2 - res = Rx.Observable.delay(new Date(), Rx.Scheduler.timeout); + * + * 3 - res = Rx.Observable.delay(5000); + * 4 - res = Rx.Observable.delay(5000, 1000, Rx.Scheduler.timeout); + * @memberOf Observable# + * @param {Number} dueTime Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) by which to shift the observable sequence. + * @param {Scheduler} [scheduler] Scheduler to run the delay timers on. If not specified, the timeout scheduler is used. + * @returns {Observable} Time-shifted sequence. + */ + delay(dueTime: Date, scheduler?: IScheduler): Observable; + /** + * Time shifts the observable sequence by dueTime. The relative time intervals between the values are preserved. + * + * @example + * 1 - res = Rx.Observable.delay(new Date()); + * 2 - res = Rx.Observable.delay(new Date(), Rx.Scheduler.timeout); + * + * 3 - res = Rx.Observable.delay(5000); + * 4 - res = Rx.Observable.delay(5000, 1000, Rx.Scheduler.timeout); + * @memberOf Observable# + * @param {Number} dueTime Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) by which to shift the observable sequence. + * @param {Scheduler} [scheduler] Scheduler to run the delay timers on. If not specified, the timeout scheduler is used. + * @returns {Observable} Time-shifted sequence. + */ + delay(dueTime: number, scheduler?: IScheduler): Observable; + + /** + * Time shifts the observable sequence based on a subscription delay and a delay selector function for each element. + * + * @example + * 1 - res = source.delayWithSelector(function (x) { return Rx.Scheduler.timer(5000); }); // with selector only + * 1 - res = source.delayWithSelector(Rx.Observable.timer(2000), function (x) { return Rx.Observable.timer(x); }); // with delay and selector + * + * @param {Observable} [subscriptionDelay] Sequence indicating the delay for the subscription to the source. + * @param {Function} delayDurationSelector Selector function to retrieve a sequence indicating the delay for each given element. + * @returns {Observable} Time-shifted sequence. + */ + delay(delayDurationSelector: (item: T) => ObservableOrPromise): Observable; + + /** + * Time shifts the observable sequence based on a subscription delay and a delay selector function for each element. + * + * @example + * 1 - res = source.delayWithSelector(function (x) { return Rx.Scheduler.timer(5000); }); // with selector only + * 1 - res = source.delayWithSelector(Rx.Observable.timer(2000), function (x) { return Rx.Observable.timer(x); }); // with delay and selector + * + * @param {Observable} [subscriptionDelay] Sequence indicating the delay for the subscription to the source. + * @param {Function} delayDurationSelector Selector function to retrieve a sequence indicating the delay for each given element. + * @returns {Observable} Time-shifted sequence. + */ + delay(subscriptionDelay: Observable, delayDurationSelector: (item: T) => ObservableOrPromise): Observable; + } + + export interface Observable { + /** + * Ignores values from an observable sequence which are followed by another value before dueTime. + * @param {Number} dueTime Duration of the debounce period for each value (specified as an integer denoting milliseconds). + * @param {Scheduler} [scheduler] Scheduler to run the debounce timers on. If not specified, the timeout scheduler is used. + * @returns {Observable} The debounced sequence. + */ + debounce(dueTime: number, scheduler?: IScheduler): Observable; + + /** + * Ignores values from an observable sequence which are followed by another value within a computed throttle duration. + * @param {Function} durationSelector Selector function to retrieve a sequence indicating the throttle duration for each given element. + * @returns {Observable} The debounced sequence. + */ + debounce(debounceDurationSelector: (item: T) => ObservableOrPromise): Observable; + } + export interface Observable { /** * Projects each element of an observable sequence into zero or more windows which are produced based on timing information. @@ -79,6 +189,139 @@ declare module Rx { timeInterval(scheduler?: IScheduler): Observable>; } + export interface Timestamp { + value: T; + timestamp: number; + } + + export interface Observable { + /** + * Records the timestamp for each value in an observable sequence. + * + * @example + * 1 - res = source.timestamp(); // produces { value: x, timestamp: ts } + * 2 - res = source.timestamp(Rx.Scheduler.default); + * + * @param {Scheduler} [scheduler] Scheduler used to compute timestamps. If not specified, the default scheduler is used. + * @returns {Observable} An observable sequence with timestamp information on values. + */ + timestamp(scheduler?: IScheduler): Observable>; + } + + export interface Observable { + /** + * Samples the observable sequence at each interval. + * + * @example + * 1 - res = source.sample(sampleObservable); // Sampler tick sequence + * 2 - res = source.sample(5000); // 5 seconds + * 2 - res = source.sample(5000, Rx.Scheduler.timeout); // 5 seconds + * + * @param {Mixed} intervalOrSampler Interval at which to sample (specified as an integer denoting milliseconds) or Sampler Observable. + * @param {Scheduler} [scheduler] Scheduler to run the sampling timer on. If not specified, the timeout scheduler is used. + * @returns {Observable} Sampled observable sequence. + */ + sample(intervalOrSampler: number, scheduler?: IScheduler): Observable; + /** + * Samples the observable sequence at each interval. + * + * @example + * 1 - res = source.sample(sampleObservable); // Sampler tick sequence + * 2 - res = source.sample(5000); // 5 seconds + * 2 - res = source.sample(5000, Rx.Scheduler.timeout); // 5 seconds + * + * @param {Mixed} intervalOrSampler Interval at which to sample (specified as an integer denoting milliseconds) or Sampler Observable. + * @param {Scheduler} [scheduler] Scheduler to run the sampling timer on. If not specified, the timeout scheduler is used. + * @returns {Observable} Sampled observable sequence. + */ + sample(sampler: Observable, scheduler?: IScheduler): Observable; + /** + * Samples the observable sequence at each interval. + * + * @example + * 1 - res = source.sample(sampleObservable); // Sampler tick sequence + * 2 - res = source.sample(5000); // 5 seconds + * 2 - res = source.sample(5000, Rx.Scheduler.timeout); // 5 seconds + * + * @param {Mixed} intervalOrSampler Interval at which to sample (specified as an integer denoting milliseconds) or Sampler Observable. + * @param {Scheduler} [scheduler] Scheduler to run the sampling timer on. If not specified, the timeout scheduler is used. + * @returns {Observable} Sampled observable sequence. + */ + throttleLatest(interval: number, scheduler?: IScheduler): Observable; + /** + * Samples the observable sequence at each interval. + * + * @example + * 1 - res = source.sample(sampleObservable); // Sampler tick sequence + * 2 - res = source.sample(5000); // 5 seconds + * 2 - res = source.sample(5000, Rx.Scheduler.timeout); // 5 seconds + * + * @param {Mixed} intervalOrSampler Interval at which to sample (specified as an integer denoting milliseconds) or Sampler Observable. + * @param {Scheduler} [scheduler] Scheduler to run the sampling timer on. If not specified, the timeout scheduler is used. + * @returns {Observable} Sampled observable sequence. + */ + throttleLatest(sampler: Observable, scheduler?: IScheduler): Observable; + } + + export interface Observable { + /** + * Returns the source observable sequence or the other observable sequence if dueTime elapses. + * @param {Number} dueTime Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) when a timeout occurs. + * @param {Scheduler} [scheduler] Scheduler to run the timeout timers on. If not specified, the timeout scheduler is used. + * @returns {Observable} The source sequence switching to the other sequence in case of a timeout. + */ + timeout(dueTime: Date, scheduler?: IScheduler): Observable; + + /** + * Returns the source observable sequence or the other observable sequence if dueTime elapses. + * @param {Number} dueTime Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) when a timeout occurs. + * @param {Observable} [other] Sequence to return in case of a timeout. If not specified, a timeout error throwing sequence will be used. + * @param {Scheduler} [scheduler] Scheduler to run the timeout timers on. If not specified, the timeout scheduler is used. + * @returns {Observable} The source sequence switching to the other sequence in case of a timeout. + */ + timeout(dueTime: Date, other?: Observable, scheduler?: IScheduler): Observable; + /** + * Returns the source observable sequence or the other observable sequence if dueTime elapses. + * @param {Number} dueTime Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) when a timeout occurs. + * @param {Observable} [other] Sequence to return in case of a timeout. If not specified, a timeout error throwing sequence will be used. + * @param {Scheduler} [scheduler] Scheduler to run the timeout timers on. If not specified, the timeout scheduler is used. + * @returns {Observable} The source sequence switching to the other sequence in case of a timeout. + */ + timeout(dueTime: number, scheduler?: IScheduler): Observable; + /** + * Returns the source observable sequence or the other observable sequence if dueTime elapses. + * @param {Number} dueTime Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) when a timeout occurs. + * @param {Observable} [other] Sequence to return in case of a timeout. If not specified, a timeout error throwing sequence will be used. + * @param {Scheduler} [scheduler] Scheduler to run the timeout timers on. If not specified, the timeout scheduler is used. + * @returns {Observable} The source sequence switching to the other sequence in case of a timeout. + */ + timeout(dueTime: number, other?: Observable, scheduler?: IScheduler): Observable; + + /** + * Returns the source observable sequence, switching to the other observable sequence if a timeout is signaled. + * @param {Function} timeoutDurationSelector Selector to retrieve an observable sequence that represents the timeout between the current element and the next element. + * @returns {Observable} The source sequence switching to the other sequence in case of a timeout. + */ + timeout(timeoutdurationSelector: (item: T) => Observable): Observable; + + /** + * Returns the source observable sequence, switching to the other observable sequence if a timeout is signaled. + * @param {Function} timeoutDurationSelector Selector to retrieve an observable sequence that represents the timeout between the current element and the next element. + * @param {Observable} other Sequence to return in case of a timeout. If not provided, this is set to Observable.throwException(). + * @returns {Observable} The source sequence switching to the other sequence in case of a timeout. + */ + timeout(timeoutdurationSelector: (item: T) => Observable, other: Observable): Observable; + + /** + * Returns the source observable sequence, switching to the other observable sequence if a timeout is signaled. + * @param {Observable} [firstTimeout] Observable sequence that represents the timeout for the first element. If not provided, this defaults to Observable.never(). + * @param {Function} timeoutDurationSelector Selector to retrieve an observable sequence that represents the timeout between the current element and the next element. + * @param {Observable} [other] Sequence to return in case of a timeout. If not provided, this is set to Observable.throwException(). + * @returns {Observable} The source sequence switching to the other sequence in case of a timeout. + */ + timeout(firstTimeout: Observable, timeoutdurationSelector: (item: T) => Observable, other?: Observable): Observable; + } + export interface ObservableStatic { /** * Generates an observable sequence by iterating a state from an initial state until the condition fails. @@ -279,5 +522,15 @@ declare module Rx { takeUntilWithTime(duration: number, scheduler?: IScheduler): Observable; } + export interface Observable { + /** + * Returns an Observable that emits only the first item emitted by the source Observable during sequential time windows of a specified duration. + * @param {Number} windowDuration time to wait before emitting another item after emitting the last item + * @param {Scheduler} [scheduler] the Scheduler to use internally to manage the timers that handle timeout for each item. If not provided, defaults to Scheduler.timeout. + * @returns {Observable} An Observable that performs the throttle operation. + */ + throttle(windowDuration: number, scheduler?: IScheduler): Observable; + } + } declare module "rx.time" { export = Rx; }