From a1223529d4a43f171861ea629c06062e19cf5bf1 Mon Sep 17 00:00:00 2001 From: Andrew Gaspar Date: Wed, 19 Jun 2013 23:30:21 -0700 Subject: [PATCH] Updated q so that the interfaces fell underneath the modules --- q/Q-tests.ts | 2 +- q/Q.d.ts | 102 ++++++++++++++++++++++---------------------- q/q.module-tests.ts | 3 +- 3 files changed, 53 insertions(+), 54 deletions(-) diff --git a/q/Q-tests.ts b/q/Q-tests.ts index 65a19d008..cd3cc653e 100644 --- a/q/Q-tests.ts +++ b/q/Q-tests.ts @@ -40,7 +40,7 @@ Q.fcall(function () { }) }).done(); Q.allResolved([]) -.then(function (promises: Qpromise[]) { +.then(function (promises: Q.Promise[]) { promises.forEach(function (promise) { if (promise.isFulfilled()) { var value = promise.valueOf(); diff --git a/q/Q.d.ts b/q/Q.d.ts index f1835241d..a0ecb75ce 100644 --- a/q/Q.d.ts +++ b/q/Q.d.ts @@ -1,68 +1,68 @@ // Type definitions for Q // Project: https://github.com/kriskowal/q -// Definitions by: Barrie Nemetchek +// Definitions by: Barrie Nemetchek, Andrew Gaspar // Definitions: https://github.com/borisyankov/DefinitelyTyped -interface Qdeferred { - promise: Qpromise; - resolve(value: any): any; - reject(reason: any); - notify(value: any); - makeNodeResolver(): () => void; -} - -interface Qpromise { - fail(errorCallback: Function): Qpromise; - fin(finallyCallback: Function): Qpromise; - then(onFulfilled?: Function, onRejected?: Function, onProgress?: Function): Qpromise; - spread(onFulfilled: Function, onRejected?: Function): Qpromise; - catch(onRejected: Function): Qpromise; - progress(onProgress: Function): Qpromise; - done(onFulfilled?: Function, onRejected?: Function, onProgress?: Function): Qpromise; - get (propertyName: String): Qpromise; - set (propertyName: String, value: any): Qpromise; - delete (propertyName: String): Qpromise; - post(methodName: String, args: any[]): Qpromise; - invoke(methodName: String, ...args: any[]): Qpromise; - keys(): Qpromise; - fapply(args: any[]): Qpromise; - fcall(method: Function, ...args: any[]): Qpromise; - timeout(ms: number): Qpromise; - delay(ms: number): Qpromise; - isFulfilled(): bool; - isRejected(): bool; - isPending(): bool; - valueOf(): any; -} - -declare function Q(value: any): Qpromise; +declare function Q(value: any): Q.Promise; declare module Q { - export function when(value: any, onFulfilled: Function, onRejected?: Function): Qpromise; + interface Deferred { + promise: Promise; + resolve(value: any): any; + reject(reason: any); + notify(value: any); + makeNodeResolver(): () => void; + } + + interface Promise { + fail(errorCallback: Function): Promise; + fin(finallyCallback: Function): Promise; + then(onFulfilled?: Function, onRejected?: Function, onProgress?: Function): Promise; + spread(onFulfilled: Function, onRejected?: Function): Promise; + catch(onRejected: Function): Promise; + progress(onProgress: Function): Promise; + done(onFulfilled?: Function, onRejected?: Function, onProgress?: Function): Promise; + get(propertyName: String): Promise; + set(propertyName: String, value: any): Promise; + delete(propertyName: String): Promise; + post(methodName: String, args: any[]): Promise; + invoke(methodName: String, ...args: any[]): Promise; + keys(): Promise; + fapply(args: any[]): Promise; + fcall(method: Function, ...args: any[]): Promise; + timeout(ms: number): Promise; + delay(ms: number): Promise; + isFulfilled(): bool; + isRejected(): bool; + isPending(): bool; + valueOf(): any; + } + + export function when(value: any, onFulfilled: Function, onRejected?: Function): Promise; //export function try(method: Function, ...args: any[]): Qpromise; <- This is broken currently - not sure how to fix. - export function fbind(method: Function, ...args: any[]): Qpromise; - export function fcall(method: Function, ...args: any[]): Qpromise; - export function nfbind(nodeFunction: Function): (...args: any[]) => Qpromise; - export function nfcall(nodeFunction: Function, ...args: any[]): Qpromise; - export function ninvoke(nodeModule: any, functionName: string, ...args: any[]): Qpromise; - export function all(promises: Qpromise[]): Qpromise; - export function allResolved(promises: Qpromise[]): Qpromise; - export function spread(onFulfilled: Function, onRejected: Function): Qpromise; - export function timeout(ms: number): Qpromise; - export function delay(ms: number): Qpromise; - export function delay(value: any, ms: number): Qpromise; + export function fbind(method: Function, ...args: any[]): Promise; + export function fcall(method: Function, ...args: any[]): Promise; + export function nfbind(nodeFunction: Function): (...args: any[]) => Promise; + export function nfcall(nodeFunction: Function, ...args: any[]): Promise; + export function ninvoke(nodeModule: any, functionName: string, ...args: any[]): Promise; + export function all(promises: Promise[]): Promise; + export function allResolved(promises: Promise[]): Promise; + export function spread(onFulfilled: Function, onRejected: Function): Promise; + export function timeout(ms: number): Promise; + export function delay(ms: number): Promise; + export function delay(value: any, ms: number): Promise; export function isFulfilled(): bool; export function isRejected(): bool; export function isPending(): bool; export function valueOf(): any; - export function defer(): Qdeferred; - export function reject(): Qpromise; - export function promise(factory: { resolve: Function; reject: Function; notify: Function; }): Qpromise; + export function defer(): Deferred; + export function reject(): Promise; + export function promise(factory: { resolve: Function; reject: Function; notify: Function; }): Promise; export function isPromise(value: any): bool; - export function async(generatorFunction: any): Qdeferred; + export function async(generatorFunction: any): Deferred; export function nextTick(callback: Function); export var oneerror: any; export var longStackJumpLimit: number; - export function resolve(object?: Qpromise); + export function resolve(object?: Promise); } declare module "q" { diff --git a/q/q.module-tests.ts b/q/q.module-tests.ts index 2d32febca..fe4764e76 100644 --- a/q/q.module-tests.ts +++ b/q/q.module-tests.ts @@ -44,8 +44,7 @@ q.fcall(function () { }) // Handle any error from step1 through step4 }).done(); -q.allResolved([]) -.then(function (promises: Qpromise[]) { +q.allResolved([]).then(function (promises) { promises.forEach(function (promise) { if (promise.isFulfilled()) { var value = promise.valueOf();