rx.async: added tests; added toPromise operator

This commit is contained in:
Igor Oleinikov
2014-01-06 22:49:12 +04:00
parent 6d32569306
commit f121d2eecc
2 changed files with 102 additions and 4 deletions
+22 -4
View File
@@ -1,6 +1,6 @@
///<reference path="rx.d.ts" />
// Type definitions for RxJS-Async package 2.2
// Type definitions for RxJS-Async package 2.2.11
// Project: http://rx.codeplex.com/
// Definitions by: zoetrope <https://github.com/zoetrope>
// Revision by: Igor Oleinikov <https://github.com/Igorbek>
@@ -84,11 +84,29 @@ declare module Rx {
fromEvent<T>(element: Node, eventName: string, selector?: (arguments: any[]) => T): Observable<T>;
fromEventPattern<T>(addHandler: (handler: Function) => void, removeHandler: (handler: Function) => void, selector?: (arguments: any[])=>T): Observable<T>;
fromPromise<T>(promise: Promise<T>): Observable<T>;
fromPromise<T>(promise: IPromise<T>): Observable<T>;
fromPromise<T>(promise: any): Observable<T>;
}
interface Promise<T> {
then(onFulfill: (value: T) => any, onReject?: (reason: any) => any): any;
interface Observable<T> {
/**
* Converts an existing observable sequence to an ES6 Compatible Promise
* @example
* var promise = Rx.Observable.return(42).toPromise(RSVP.Promise);
* @param The constructor of the promise
* @returns An ES6 compatible promise with the last value from the observable sequence.
*/
toPromise<TPromise extends IPromise<T>>(promiseCtor: { new (resolver: (resolvePromise: (value: T) => void, rejectPromise: (reason: any) => void) => void): TPromise; }): TPromise;
toPromise(promiseCtor: { new (resolver: (resolvePromise: (value: T) => void, rejectPromise: (reason: any) => void) => void): IPromise<T>; }): IPromise<T>;
}
/**
* Promise A+
*/
export interface IPromise<T> {
then<R>(onFulfilled?: (value: T) => IPromise<R>, onRejected?: (reason: any) => IPromise<R>): IPromise<R>;
then<R>(onFulfilled?: (value: T) => IPromise<R>, onRejected?: (reason: any) => R): IPromise<R>;
then<R>(onFulfilled?: (value: T) => R, onRejected?: (reason: any) => IPromise<R>): IPromise<R>;
then<R>(onFulfilled?: (value: T) => R, onRejected?: (reason: any) => R): IPromise<R>;
}
}