Merge pull request #1823 from Igorbek/master

Definitions of spec of Promises/A+; Updated RxJS
This commit is contained in:
Igorbek
2014-03-10 11:24:41 -07:00
4 changed files with 101 additions and 5 deletions
+81
View File
@@ -0,0 +1,81 @@
/// <reference path="promises-a-plus.d.ts"/>
/// <reference path="../rx.js/rx.async.d.ts"/>
/// <reference path="../es6-promises/es6-promises.d.ts"/>
/// <reference path="../q/Q.d.ts"/>
/// <reference path="../when/when.d.ts"/>
var thenNum: PromisesAPlus.Thenable<number>;
var thenStr: PromisesAPlus.Thenable<string>;
var thenBool: PromisesAPlus.Thenable<boolean>;
var impl: PromisesAPlus.PromiseImpl;
declare class PromiseImpl<R> {
constructor(resolver: (resolvePromise: (value: R) => void, rejectPromise: (reason: any) => void) => void);
then<U>(onFulfill: (value: R) => PromiseImpl<U>, onReject: (error: any) => PromiseImpl<U>): PromiseImpl<U>;
then<U>(onFulfill: (value: R) => PromiseImpl<U>, onReject?: (error: any) => U): PromiseImpl<U>;
then<U>(onFulfill: (value: R) => U, onReject: (error: any) => PromiseImpl<U>): PromiseImpl<U>;
then<U>(onFulfill?: (value: R) => U, onReject?: (error: any) => U): PromiseImpl<U>;
}
function testCompatibleWithPromiseImpl() {
var pNum: PromiseImpl<number> = thenNum;
thenNum = pNum;
impl = PromiseImpl;
}
function testCompatibleWithRxJS() {
// from spec to Rx
var rxThenNum: Rx.IPromise<number> = thenNum;
var rxThenStr: Rx.IPromise<string> = thenStr;
// from Rx to spec
thenNum = rxThenNum;
thenStr = rxThenStr;
var obsNum: Rx.Observable<number>;
// implementation usage
thenNum = obsNum.toPromise<PromisesAPlus.Thenable<number>>(impl);
thenNum = obsNum.toPromise(impl);
obsNum.toPromise(PromiseImpl);
}
function testCompatibleWithES6Promises() {
// from spec to ES6
var es6ThenNum: Thenable<number> = thenNum;
var es6ThenStr: Thenable<string> = thenStr;
// from ES6 to spec
thenNum = es6ThenNum;
thenStr = es6ThenStr;
// implementation
impl = Promise;
}
function testCompatibleWithQ() {
// from spec to ES6
var qThenNum: Q.IPromise<number> = thenNum;
var qThenStr: Q.IPromise<string> = thenStr;
// from ES6 to spec
thenNum = qThenNum;
thenStr = qThenStr;
// there's no standart implementation with constructor behaviour
}
function testCompatibleWithWhen() {
var whenPromiseNum: When.Promise<number>;
var whenPromiseStr: When.Promise<string>;
// from ES6 to spec
thenNum = whenPromiseNum;
thenStr = whenPromiseStr;
// there's no standart implementation with constructor behaviour
}
+16
View File
@@ -0,0 +1,16 @@
declare module PromisesAPlus {
interface PromiseCtor {
<T>(resolver: (resolvePromise: (value: T) => void, rejectPromise: (reason: any) => void) => void): Thenable<T>;
}
interface PromiseImpl {
new <T>(resolver: (resolvePromise: (value: T) => void, rejectPromise: (reason: any) => void) => void): Thenable<T>;
}
interface Thenable<R> {
then<U>(onFulfill: (value: R) => Thenable<U>, onReject: (error: any) => Thenable<U>): Thenable<U>;
then<U>(onFulfill: (value: R) => Thenable<U>, onReject?: (error: any) => U): Thenable<U>;
then<U>(onFulfill: (value: R) => U, onReject: (error: any) => Thenable<U>): Thenable<U>;
then<U>(onFulfill?: (value: R) => U, onReject?: (error: any) => U): Thenable<U>;
}
}
+3 -3
View File
@@ -104,9 +104,9 @@ declare module Rx {
* 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) => 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>;
}
}
+1 -2
View File
@@ -1,4 +1,4 @@
// Type definitions for RxJS
// Type definitions for RxJS v2.2.13
// Project: http://rx.codeplex.com/
// Definitions by: gsino <http://www.codeplex.com/site/users/view/gsino>
// Definitions by: Igor Oleinikov <https://github.com/Igorbek>
@@ -167,7 +167,6 @@ declare module Rx {
// Current Thread IScheduler
interface ICurrentThreadScheduler extends IScheduler {
scheduleRequired(): boolean;
ensureTrampoline(action: () =>IDisposable): IDisposable;
}
// Notifications