From 4887a99db3909a6a53348831cb551007d8dcaee2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20de=20Campredon?= Date: Wed, 15 Jan 2014 16:58:14 +0100 Subject: [PATCH] Renaming to respect conventions, add Readme --- README.md | 1 + ...romises-tests.ts => es6-promises-tests.ts} | 2 + ...params => es6-promises-tests.ts.tscparams} | 0 es6-promises/es6-promises.d.ts | 95 +++++++++++++++++++ es6-promises/promises.d.ts | 39 -------- 5 files changed, 98 insertions(+), 39 deletions(-) rename es6-promises/{promises-tests.ts => es6-promises-tests.ts} (98%) rename es6-promises/{promises-tests.ts.tscparams => es6-promises-tests.ts.tscparams} (100%) create mode 100644 es6-promises/es6-promises.d.ts delete mode 100644 es6-promises/promises.d.ts diff --git a/README.md b/README.md index 27d6be4e4a..d97c6c2d0d 100755 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ List of Definitions * [EaselJS](http://www.createjs.com/#!/EaselJS) (by [Pedro Ferreira](https://bitbucket.org/drk4)) * [ember.js](http://emberjs.com/) (by [Boris Yankov](https://github.com/borisyankov)) * [EpicEditor](http://epiceditor.com/) (by [Boris Yankov](https://github.com/borisyankov)) +* [ES6-Promises](https://github.com/jakearchibald/ES6-Promises) (by [François de Campredon](https://github.com/fdecampredon/)) * [expect.js](https://github.com/LearnBoost/expect.js) (by [Teppei Sato](https://github.com/teppeis)) * [expectations](https://github.com/spmason/expectations) (by [vvakame](https://github.com/vvakame)) * [Express](http://expressjs.com/) (by [Boris Yankov](https://github.com/borisyankov)) diff --git a/es6-promises/promises-tests.ts b/es6-promises/es6-promises-tests.ts similarity index 98% rename from es6-promises/promises-tests.ts rename to es6-promises/es6-promises-tests.ts index 9f1e05dc26..fd11605722 100644 --- a/es6-promises/promises-tests.ts +++ b/es6-promises/es6-promises-tests.ts @@ -1,3 +1,5 @@ +/// + var promiseString: Promise, promiseStringArr: Promise, arrayOfPromise: Promise[], diff --git a/es6-promises/promises-tests.ts.tscparams b/es6-promises/es6-promises-tests.ts.tscparams similarity index 100% rename from es6-promises/promises-tests.ts.tscparams rename to es6-promises/es6-promises-tests.ts.tscparams diff --git a/es6-promises/es6-promises.d.ts b/es6-promises/es6-promises.d.ts new file mode 100644 index 0000000000..fc013817d2 --- /dev/null +++ b/es6-promises/es6-promises.d.ts @@ -0,0 +1,95 @@ +// Type definitions for es6-promises +// Project: https://github.com/jakearchibald/ES6-Promises +// Definitions by: François de Campredon +// Definitions: https://github.com/borisyankov/DefinitelyTyped + + +interface Thenable { + then(onFulfill: (value: R) => Thenable, onReject?: (error: any) => void): Thenable; + then(onFulfill: (value: R) => U, onReject?: (error: any) => void): Thenable; + then(onFulfill: (value: R) => Thenable, onReject?: (error: any) => Thenable): Thenable; + then(onFulfill: (value: R) => Thenable, onReject?: (error: any) => U): Thenable; + then(onFulfill: (value: R) => U, onReject?: (error: any) => Thenable): Thenable; + then(onFulfill: (value: R) => U, onReject?: (error: any) => U): Thenable; +} + +declare class Promise implements Thenable { + /** + * @param resolve Your promise is fulfilled with obj + * @rejectYour promise is rejected with obj. For consistency and debugging (eg stack traces), obj should be an instanceof Error. Any errors thrown in the constructor callback will be implicitly passed to reject(). + */ + constructor(callback: (resolve : (result: R) => void, reject: (error: any) => void) => void); + /** + * @param resolve Your promise will be fulfilled/rejected with the outcome of thenable reject(obj) + * @rejectYour promise is rejected with obj. For consistency and debugging (eg stack traces), obj should be an instanceof Error. Any errors thrown in the constructor callback will be implicitly passed to reject(). + */ + constructor(callback: (resolve : (result: Thenable) => void, reject: (error: any) => void) => void); + + + /** + * onFullFill is called when/if "promise" resolves. onRejected is called when/if "promise" rejects. + * Both are optional, if either/both are omitted the next onFulfilled/onRejected in the chain is called. + * Both callbacks have a single parameter , the fulfillment value or rejection reason. + * "then" returns a new promise equivalent to the value you return from onFulfilled/onRejected after being passed through Promise.resolve. + * If an error is thrown in the callback, the returned promise rejects with that error. + * + * @param onFullFill called when/if "promise" resolves + * @param onReject called when/if "promise" rejects + */ + then(onFulfill: (value: R) => Thenable, onReject?: (error: any) => void): Promise; + then(onFulfill: (value: R) => U, onReject?: (error: any) => void): Promise; + then(onFulfill: (value: R) => Thenable, onReject?: (error: any) => Thenable): Promise; + then(onFulfill: (value: R) => Thenable, onReject?: (error: any) => U): Promise; + then(onFulfill: (value: R) => U, onReject?: (error: any) => Thenable): Promise; + then(onFulfill: (value: R) => U, onReject?: (error: any) => U): Promise; + + + /** + * Sugar for promise.then(undefined, onRejected) + * + * @param onReject called when/if "promise" rejects + */ + catch(onReject?: (error: any) => Thenable): Promise + catch(onReject?: (error: any) => U): Promise +} + +declare module Promise { + + /** + * Returns promise (only if promise.constructor == Promise) + */ + function cast(promise: Promise): Promise; + /** + * Make a promise that fulfills to obj. + */ + function cast(object: R): Promise; + + + /** + * Make a new promise from the thenable. + * A thenable is promise-like in as far as it has a "then" method. + * This also creates a new promise if you pass it a genuine JavaScript promise, making it less efficient for casting than Promise.cast. + */ + function resolve(thenable: Thenable): Promise; + /** + * Make a promise that fulfills to obj. Same as Promise.cast(obj) in this situation. + */ + function resolve(object: R): Promise; + + /** + * Make a promise that rejects to obj. For consistency and debugging (eg stack traces), obj should be an instanceof Error + */ + function reject(error: any): Promise; + + /** + * Make a promise that fulfills when every item in the array fulfills, and rejects if (and when) any item rejects. + * Eadd array item is passed to Promise.cast, so the array can be a mixture of promise-like objects and other objects. + * The fulfillment value is an array (in order) of fulfillment values. The rejection value is the first rejection value. + */ + function all(promises: Promise[]): Promise; + + /** + * Make a Promise that fulfills when any item fulfills, and rejects if any item rejects. + */ + function race(promises: Promise[]): Promise; +} \ No newline at end of file diff --git a/es6-promises/promises.d.ts b/es6-promises/promises.d.ts deleted file mode 100644 index c24844e6fd..0000000000 --- a/es6-promises/promises.d.ts +++ /dev/null @@ -1,39 +0,0 @@ -interface Thenable { - then(onFulfill: (value: R) => Thenable, onReject?: (error: any) => void): Thenable; - then(onFulfill: (value: R) => U, onReject?: (error: any) => void): Thenable; - then(onFulfill: (value: R) => Thenable, onReject?: (error: any) => Thenable): Thenable; - then(onFulfill: (value: R) => Thenable, onReject?: (error: any) => U): Thenable; - then(onFulfill: (value: R) => U, onReject?: (error: any) => Thenable): Thenable; - then(onFulfill: (value: R) => U, onReject?: (error: any) => U): Thenable; -} - -declare class Promise implements Thenable { - constructor(callback: (resolve : (result: R) => void, reject: (error: any) => void) => void); - constructor(callback: (resolve : (result: Thenable) => void, reject: (error: any) => void) => void); - - then(onFulfill: (value: R) => Thenable, onReject?: (error: any) => void): Promise; - then(onFulfill: (value: R) => U, onReject?: (error: any) => void): Promise; - then(onFulfill: (value: R) => Thenable, onReject?: (error: any) => Thenable): Promise; - then(onFulfill: (value: R) => Thenable, onReject?: (error: any) => U): Promise; - then(onFulfill: (value: R) => U, onReject?: (error: any) => Thenable): Promise; - then(onFulfill: (value: R) => U, onReject?: (error: any) => U): Promise; - - catch(onReject?: (error: any) => Thenable): Promise - catch(onReject?: (error: any) => U): Promise -} - -declare module Promise { - - - function cast(promise: Promise): Promise; - function cast(object: R): Promise; - - function resolve(thenable: Thenable): Promise; - function resolve(object: R): Promise; - - function reject(error: any): Promise; - - function all(promises: Promise[]): Promise; - - function race(promises: Promise[]): Promise; -} \ No newline at end of file