From a94c9ab2224c677eb0db6d82ead5447b42deb114 Mon Sep 17 00:00:00 2001 From: Andrew Gaspar Date: Sat, 23 Mar 2013 03:13:57 -0500 Subject: [PATCH 1/5] Added type definitions that expose q as a CommonJS module. Under Qnode folder. --- Qnode/q.d.ts | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Qnode/q.d.ts diff --git a/Qnode/q.d.ts b/Qnode/q.d.ts new file mode 100644 index 0000000000..48fc11a5cb --- /dev/null +++ b/Qnode/q.d.ts @@ -0,0 +1,58 @@ +// Type definitions for Q that can be imported in node.js +// Project: https://github.com/kriskowal/q +// Definitions by: Barrie Nemetchek and Andrew Gaspar +// Definitions: https://github.com/AndrewGaspar/DefinitelyTyped + +interface Qdeferred { + promise: Qpromise; + resolve(value: any): any; + reject(reason: any); + notify(value: any); + makeNodeResolver(): Function; +} + +interface Qpromise { + fail(errorCallback: Function): Qpromise; + fin(finallyCallback: Function): Qpromise; + then(onFulfilled: Function, onRejected?: Function, onProgress?: 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; +} + +export function try(method: Function, ...args: any[]): Qpromise; +export function fbind(method: Function, ...args: any[]): Qpromise; +export function fcall(method: Function, ...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 isFulfilled(): bool; +export function isRejected(): bool; +export function isPending(): bool; +export function valueOf(): any; +export function defer(): Qdeferred; +export function (value: any): Qpromise; +export function reject(): Qpromise; +export function promise(factory: { resolve: Function; reject: Function; notify: Function; }): Qpromise; +export function isPromise(value: any): bool; +export function async(generatorFunction: any): Qdeferred; +export function nextTick(callback: Function); +export var oneerror: any; +export var longStackJumpLimit: number; \ No newline at end of file From 362cefbcc0919dc8c177c1cdb102daf62f371a38 Mon Sep 17 00:00:00 2001 From: Andrew Gaspar Date: Sat, 23 Mar 2013 03:18:39 -0500 Subject: [PATCH 2/5] Moved q declaration for CommonJS to qcommon --- {Qnode => qcommon}/q.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename {Qnode => qcommon}/q.d.ts (97%) diff --git a/Qnode/q.d.ts b/qcommon/q.d.ts similarity index 97% rename from Qnode/q.d.ts rename to qcommon/q.d.ts index 48fc11a5cb..9add54ab8e 100644 --- a/Qnode/q.d.ts +++ b/qcommon/q.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Q that can be imported in node.js +// Type definitions for q that meet the CommonJS module format. // Project: https://github.com/kriskowal/q // Definitions by: Barrie Nemetchek and Andrew Gaspar // Definitions: https://github.com/AndrewGaspar/DefinitelyTyped From 8fd794abffa8bd2de86a14efb1bae70b66296524 Mon Sep 17 00:00:00 2001 From: Andrew Gaspar Date: Sat, 23 Mar 2013 16:22:55 -0500 Subject: [PATCH 3/5] Remove qcommon and added q.module.d.ts which declares a module 'q'. Also added a couple jasmine style tests. --- Q/q-tests.spec.ts | 27 ++++++++++++++++++++++ Q/q.module.d.ts | 26 +++++++++++++++++++++ qcommon/q.d.ts | 58 ----------------------------------------------- 3 files changed, 53 insertions(+), 58 deletions(-) create mode 100644 Q/q-tests.spec.ts create mode 100644 Q/q.module.d.ts delete mode 100644 qcommon/q.d.ts diff --git a/Q/q-tests.spec.ts b/Q/q-tests.spec.ts new file mode 100644 index 0000000000..510a50610c --- /dev/null +++ b/Q/q-tests.spec.ts @@ -0,0 +1,27 @@ +/// +/// + +import q = module("q"); + +describe("q", function () { + it("should return", function (done) { + q({ myValue: true }).then(function (obj) { + + if (obj.myValue) done(); + else done("didn't work =("); + }, + (err) => done(err)); + }); + + it("should process all", function (done: (err?) => void) { + q.all([q(1), q(2), q(3)]).then(function (arr: number[]) { + var sum = arr.reduce(function (memo, cur) { + return memo + cur; + }, 0); + + if (sum === 6) done(); + else done({ actual: sum }); + }, + (err) => done(err)); + }); +}); \ No newline at end of file diff --git a/Q/q.module.d.ts b/Q/q.module.d.ts new file mode 100644 index 0000000000..38b19aafc2 --- /dev/null +++ b/Q/q.module.d.ts @@ -0,0 +1,26 @@ +/// + +module "q" { + export function try(method: Function, ...args: any[]): Qpromise; + export function fbind(method: Function, ...args: any[]): Qpromise; + export function fcall(method: Function, ...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 isFulfilled(): bool; + export function isRejected(): bool; + export function isPending(): bool; + export function valueOf(): any; + export function defer(): Qdeferred; + export function (value: any): Qpromise; + export function reject(): Qpromise; + export function promise(factory: { resolve: Function; reject: Function; notify: Function; }): Qpromise; + export function isPromise(value: any): bool; + export function async(generatorFunction: any): Qdeferred; + export function nextTick(callback: Function); + export var oneerror: any; + export var longStackJumpLimit: number; +} \ No newline at end of file diff --git a/qcommon/q.d.ts b/qcommon/q.d.ts deleted file mode 100644 index 9add54ab8e..0000000000 --- a/qcommon/q.d.ts +++ /dev/null @@ -1,58 +0,0 @@ -// Type definitions for q that meet the CommonJS module format. -// Project: https://github.com/kriskowal/q -// Definitions by: Barrie Nemetchek and Andrew Gaspar -// Definitions: https://github.com/AndrewGaspar/DefinitelyTyped - -interface Qdeferred { - promise: Qpromise; - resolve(value: any): any; - reject(reason: any); - notify(value: any); - makeNodeResolver(): Function; -} - -interface Qpromise { - fail(errorCallback: Function): Qpromise; - fin(finallyCallback: Function): Qpromise; - then(onFulfilled: Function, onRejected?: Function, onProgress?: 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; -} - -export function try(method: Function, ...args: any[]): Qpromise; -export function fbind(method: Function, ...args: any[]): Qpromise; -export function fcall(method: Function, ...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 isFulfilled(): bool; -export function isRejected(): bool; -export function isPending(): bool; -export function valueOf(): any; -export function defer(): Qdeferred; -export function (value: any): Qpromise; -export function reject(): Qpromise; -export function promise(factory: { resolve: Function; reject: Function; notify: Function; }): Qpromise; -export function isPromise(value: any): bool; -export function async(generatorFunction: any): Qdeferred; -export function nextTick(callback: Function); -export var oneerror: any; -export var longStackJumpLimit: number; \ No newline at end of file From 105af2df70bc6047245373e9eb2a2603d62595e0 Mon Sep 17 00:00:00 2001 From: Andrew Gaspar Date: Sat, 23 Mar 2013 16:30:49 -0500 Subject: [PATCH 4/5] Slight change to makeNodeResolver in q.d.ts and added a second declaration for it in jasmine to accomodate 'done' function for async funciton calls. --- Q/Q.d.ts | 2 +- jasmine/jasmine.d.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Q/Q.d.ts b/Q/Q.d.ts index f7a871ea4b..45af07fd23 100644 --- a/Q/Q.d.ts +++ b/Q/Q.d.ts @@ -8,7 +8,7 @@ interface Qdeferred { resolve(value: any): any; reject(reason: any); notify(value: any); - makeNodeResolver(); + makeNodeResolver(): Function; } interface Qpromise { diff --git a/jasmine/jasmine.d.ts b/jasmine/jasmine.d.ts index 56f41b48f1..05e4370040 100644 --- a/jasmine/jasmine.d.ts +++ b/jasmine/jasmine.d.ts @@ -7,7 +7,8 @@ declare function describe(description: string, specDefinitions: Function): void; declare function xdescribe(description: string, specDefinitions: Function): void; -declare function it(expectation: string, assertion: Function): void; +declare function it(expectation: string, assertion: () => void ): void; +declare function it(expectation: string, assertion: (done: (err?) => void) => void ): void; declare function xit(expectation: string, assertion: Function): void; declare function beforeEach(action: Function): void; From c0fb4cc5c3ebdfba1e4cd955afca0bda5b8bf9b0 Mon Sep 17 00:00:00 2001 From: Andrew Gaspar Date: Sat, 23 Mar 2013 19:08:45 -0500 Subject: [PATCH 5/5] Renamed q test file. --- Q/{q-tests.spec.ts => q.module-tests.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Q/{q-tests.spec.ts => q.module-tests.ts} (100%) diff --git a/Q/q-tests.spec.ts b/Q/q.module-tests.ts similarity index 100% rename from Q/q-tests.spec.ts rename to Q/q.module-tests.ts