From 23c057e2431b24c1504add5c1083648ed05ca485 Mon Sep 17 00:00:00 2001 From: John Reilly Date: Mon, 17 Mar 2014 15:00:39 +0000 Subject: [PATCH 1/2] jQuery: Promises promises --- jquery/jquery.d.ts | 86 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 72 insertions(+), 14 deletions(-) diff --git a/jquery/jquery.d.ts b/jquery/jquery.d.ts index 7661edc8e3..81600af7f1 100644 --- a/jquery/jquery.d.ts +++ b/jquery/jquery.d.ts @@ -297,35 +297,93 @@ interface JQueryPromise { Interface for the JQuery deferred, part of callbacks */ interface JQueryDeferred extends JQueryPromise { - // Generic versions of callbacks - always(...alwaysCallbacks: T[]): JQueryDeferred; - done(...doneCallbacks: T[]): JQueryDeferred; - fail(...failCallbacks: T[]): JQueryDeferred; + /** + * Add handlers to be called when the Deferred object is either resolved or rejected. + * + * @param alwaysCallbacks1 A function, or array of functions, that is called when the Deferred is resolved or rejected. + * @param alwaysCallbacks2 Optional additional functions, or arrays of functions, that are called when the Deferred is resolved or rejected. + */ + always(alwaysCallbacks1: T, ...alwaysCallbacks2: T[]): JQueryDeferred; + /** + * Add handlers to be called when the Deferred object is resolved. + * + * @param doneCallbacks1 A function, or array of functions, that are called when the Deferred is resolved. + * @param doneCallbacks2 Optional additional functions, or arrays of functions, that are called when the Deferred is resolved. + */ + done(doneCallbacks1: T, ...doneCallbacks2: T[]): JQueryDeferred; + /** + * Add handlers to be called when the Deferred object is rejected. + * + * @param failCallbacks1 A function, or array of functions, that are called when the Deferred is rejected. + * @param failCallbacks2 Optional additional functions, or arrays of functions, that are called when the Deferred is rejected. + */ + fail(failCallbacks1: T, ...failCallbacks2: T[]): JQueryDeferred; + /** + * Add handlers to be called when the Deferred object generates progress notifications. + * + * @param progressCallbacks A function, or array of functions, to be called when the Deferred generates progress notifications. + */ progress(...progressCallbacks: T[]): JQueryDeferred; - always(...alwaysCallbacks: any[]): JQueryDeferred; - done(...doneCallbacks: any[]): JQueryDeferred; - fail(...failCallbacks: any[]): JQueryDeferred; - progress(...progressCallbacks: any[]): JQueryDeferred; - + /** + * Call the progressCallbacks on a Deferred object with the given args. + * + * @param args Optional arguments that are passed to the progressCallbacks. + */ notify(...args: any[]): JQueryDeferred; + + /** + * Call the progressCallbacks on a Deferred object with the given context and args. + * + * @param context Context passed to the progressCallbacks as the this object. + * @param args Optional arguments that are passed to the progressCallbacks. + */ notifyWith(context: any, ...args: any[]): JQueryDeferred; + /** + * Reject a Deferred object and call any failCallbacks with the given args. + * + * @param args Optional arguments that are passed to the failCallbacks. + */ reject(...args: any[]): JQueryDeferred; + /** + * Reject a Deferred object and call any failCallbacks with the given context and args. + * + * @param context Context passed to the failCallbacks as the this object. + * @param args An optional array of arguments that are passed to the failCallbacks. + */ rejectWith(context: any, ...args: any[]): JQueryDeferred; - resolve(val: T): JQueryDeferred; + /** + * Resolve a Deferred object and call any doneCallbacks with the given args. + * + * @param args Optional arguments that are passed to the doneCallbacks. + */ resolve(...args: any[]): JQueryDeferred; + + /** + * Resolve a Deferred object and call any doneCallbacks with the given context and args. + * + * @param context Context passed to the doneCallbacks as the this object. + * @param args An optional array of arguments that are passed to the doneCallbacks. + */ resolveWith(context: any, ...args: any[]): JQueryDeferred; + /** + * Determine the current state of a Deferred object. + */ state(): string; + /** + * Return a Deferred's Promise object. + * + * @param target Object onto which the promise methods have to be attached + */ promise(target?: any): JQueryPromise; } -/* - Interface of the JQuery extension of the W3C event object -*/ - +/** + * Interface of the JQuery extension of the W3C event object + */ interface BaseJQueryEventObject extends Event { data: any; delegateTarget: Element; From ee580ff30389949110cdf192ada091e244355540 Mon Sep 17 00:00:00 2001 From: John Reilly Date: Mon, 17 Mar 2014 15:26:53 +0000 Subject: [PATCH 2/2] jQuery: As promised --- jquery/jquery.d.ts | 174 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 148 insertions(+), 26 deletions(-) diff --git a/jquery/jquery.d.ts b/jquery/jquery.d.ts index 81600af7f1..7e6c79cb3c 100644 --- a/jquery/jquery.d.ts +++ b/jquery/jquery.d.ts @@ -253,49 +253,171 @@ interface JQueryCallback { remove(callbacks: Function[]): JQueryCallback; } -/* - Allows jQuery Promises to interop with non-jQuery promises -*/ +/** + * Allows jQuery Promises to interop with non-jQuery promises + */ interface JQueryGenericPromise { - then(onFulfill: (value: T) => U, onReject?: (reason: any) => U): JQueryGenericPromise; - then(onFulfill: (value: T) => JQueryGenericPromise, onReject?: (reason: any) => U): JQueryGenericPromise; - then(onFulfill: (value: T) => U, onReject?: (reason: any) => JQueryGenericPromise): JQueryGenericPromise; - then(onFulfill: (value: T) => JQueryGenericPromise, onReject?: (reason: any) => JQueryGenericPromise): JQueryGenericPromise; + /** + * Add handlers to be called when the Deferred object is resolved, rejected, or still in progress. + * + * @param doneFilter A function that is called when the Deferred is resolved. + * @param failFilter An optional function that is called when the Deferred is rejected. + */ + then(doneFilter: (value: T) => U, failFilter?: (reason: any) => U): JQueryGenericPromise; + /** + * Add handlers to be called when the Deferred object is resolved, rejected, or still in progress. + * + * @param doneFilter A function that is called when the Deferred is resolved. + * @param failFilter An optional function that is called when the Deferred is rejected. + */ + then(doneFilter: (value: T) => JQueryGenericPromise, failFilter?: (reason: any) => U): JQueryGenericPromise; + /** + * Add handlers to be called when the Deferred object is resolved, rejected, or still in progress. + * + * @param doneFilter A function that is called when the Deferred is resolved. + * @param failFilter An optional function that is called when the Deferred is rejected. + */ + then(doneFilter: (value: T) => U, failFilter?: (reason: any) => JQueryGenericPromise): JQueryGenericPromise; + /** + * Add handlers to be called when the Deferred object is resolved, rejected, or still in progress. + * + * @param doneFilter A function that is called when the Deferred is resolved. + * @param failFilter An optional function that is called when the Deferred is rejected. + */ + then(doneFilter: (value: T) => JQueryGenericPromise, failFilter?: (reason: any) => JQueryGenericPromise): JQueryGenericPromise; } -/* - Interface for the JQuery promise, part of callbacks -*/ +/** + * Interface for the JQuery promise, part of callbacks + */ interface JQueryPromise { - // Generic versions of callbacks - always(...alwaysCallbacks: T[]): JQueryPromise; - done(...doneCallbacks: T[]): JQueryPromise; - fail(...failCallbacks: T[]): JQueryPromise; - progress(...progressCallbacks: T[]): JQueryPromise; + /** + * Add handlers to be called when the Deferred object is either resolved or rejected. + * + * @param alwaysCallbacks1 A function, or array of functions, that is called when the Deferred is resolved or rejected. + * @param alwaysCallbacks2 Optional additional functions, or arrays of functions, that are called when the Deferred is resolved or rejected. + */ + always(alwaysCallbacks1: T, ...alwaysCallbacks2: T[]): JQueryDeferred; + /** + * Add handlers to be called when the Deferred object is resolved. + * + * @param doneCallbacks1 A function, or array of functions, that are called when the Deferred is resolved. + * @param doneCallbacks2 Optional additional functions, or arrays of functions, that are called when the Deferred is resolved. + */ + done(doneCallbacks1: T, ...doneCallbacks2: T[]): JQueryDeferred; + /** + * Add handlers to be called when the Deferred object is rejected. + * + * @param failCallbacks1 A function, or array of functions, that are called when the Deferred is rejected. + * @param failCallbacks2 Optional additional functions, or arrays of functions, that are called when the Deferred is rejected. + */ + fail(failCallbacks1: T, ...failCallbacks2: T[]): JQueryDeferred; + /** + * Add handlers to be called when the Deferred object generates progress notifications. + * + * @param progressCallbacks A function, or array of functions, to be called when the Deferred generates progress notifications. + */ + progress(...progressCallbacks: T[]): JQueryDeferred; + /** + * Add handlers to be called when the Deferred object is either resolved or rejected. + * + * @param alwaysCallbacks A function, or array of functions, that is called when the Deferred is resolved or rejected. + */ always(...alwaysCallbacks: any[]): JQueryPromise; + /** + * Add handlers to be called when the Deferred object is resolved. + * + * @param doneCallbacks A function, or array of functions, that are called when the Deferred is resolved. + */ done(...doneCallbacks: any[]): JQueryPromise; + /** + * Add handlers to be called when the Deferred object is rejected. + * + * @param failCallbacks A function, or array of functions, that are called when the Deferred is rejected. + */ fail(...failCallbacks: any[]): JQueryPromise; + /** + * Add handlers to be called when the Deferred object generates progress notifications. + * + * @param progressCallbacks A function, or array of functions, to be called when the Deferred generates progress notifications. + */ progress(...progressCallbacks: any[]): JQueryPromise; // Deprecated - given no typings pipe(doneFilter?: (x: any) => any, failFilter?: (x: any) => any, progressFilter?: (x: any) => any): JQueryPromise; - then(onFulfill: (value: T) => U, onReject?: (...reasons: any[]) => U, onProgress?: (...progression: any[]) => any): JQueryPromise; - then(onFulfill: (value: T) => JQueryGenericPromise, onReject?: (...reasons: any[]) => U, onProgress?: (...progression: any[]) => any): JQueryPromise; - then(onFulfill: (value: T) => U, onReject?: (...reasons: any[]) => JQueryGenericPromise, onProgress?: (...progression: any[]) => any): JQueryPromise; - then(onFulfill: (value: T) => JQueryGenericPromise, onReject?: (...reasons: any[]) => JQueryGenericPromise, onProgress?: (...progression: any[]) => any): JQueryPromise; + /** + * Add handlers to be called when the Deferred object is resolved, rejected, or still in progress. + * + * @param doneFilter A function that is called when the Deferred is resolved. + * @param failFilter An optional function that is called when the Deferred is rejected. + * @param progressFilter An optional function that is called when progress notifications are sent to the Deferred. + */ + then(doneFilter: (value: T) => U, failFilter?: (...reasons: any[]) => U, progressFilter?: (...progression: any[]) => any): JQueryPromise; + /** + * Add handlers to be called when the Deferred object is resolved, rejected, or still in progress. + * + * @param doneFilter A function that is called when the Deferred is resolved. + * @param failFilter An optional function that is called when the Deferred is rejected. + * @param progressFilter An optional function that is called when progress notifications are sent to the Deferred. + */ + then(doneFilter: (value: T) => JQueryGenericPromise, failFilter?: (...reasons: any[]) => U, progressFilter?: (...progression: any[]) => any): JQueryPromise; + /** + * Add handlers to be called when the Deferred object is resolved, rejected, or still in progress. + * + * @param doneFilter A function that is called when the Deferred is resolved. + * @param failFilter An optional function that is called when the Deferred is rejected. + * @param progressFilter An optional function that is called when progress notifications are sent to the Deferred. + */ + then(doneFilter: (value: T) => U, failFilter?: (...reasons: any[]) => JQueryGenericPromise, progressFilter?: (...progression: any[]) => any): JQueryPromise; + /** + * Add handlers to be called when the Deferred object is resolved, rejected, or still in progress. + * + * @param doneFilter A function that is called when the Deferred is resolved. + * @param failFilter An optional function that is called when the Deferred is rejected. + * @param progressFilter An optional function that is called when progress notifications are sent to the Deferred. + */ + then(doneFilter: (value: T) => JQueryGenericPromise, failFilter?: (...reasons: any[]) => JQueryGenericPromise, progressFilter?: (...progression: any[]) => any): JQueryPromise; // Because JQuery Promises Suck - then(onFulfill: (...values: any[]) => U, onReject?: (...reasons: any[]) => U, onProgress?: (...progression: any[]) => any): JQueryPromise; - then(onFulfill: (...values: any[]) => JQueryGenericPromise, onReject?: (...reasons: any[]) => U, onProgress?: (...progression: any[]) => any): JQueryPromise; - then(onFulfill: (...values: any[]) => U, onReject?: (...reasons: any[]) => JQueryGenericPromise, onProgress?: (...progression: any[]) => any): JQueryPromise; - then(onFulfill: (...values: any[]) => JQueryGenericPromise, onReject?: (...reasons: any[]) => JQueryGenericPromise, onProgress?: (...progression: any[]) => any): JQueryPromise; + /** + * Add handlers to be called when the Deferred object is resolved, rejected, or still in progress. + * + * @param doneFilter A function that is called when the Deferred is resolved. + * @param failFilter An optional function that is called when the Deferred is rejected. + * @param progressFilter An optional function that is called when progress notifications are sent to the Deferred. + */ + then(doneFilter: (...values: any[]) => U, failFilter?: (...reasons: any[]) => U, progressFilter?: (...progression: any[]) => any): JQueryPromise; + /** + * Add handlers to be called when the Deferred object is resolved, rejected, or still in progress. + * + * @param doneFilter A function that is called when the Deferred is resolved. + * @param failFilter An optional function that is called when the Deferred is rejected. + * @param progressFilter An optional function that is called when progress notifications are sent to the Deferred. + */ + then(doneFilter: (...values: any[]) => JQueryGenericPromise, failFilter?: (...reasons: any[]) => U, progressFilter?: (...progression: any[]) => any): JQueryPromise; + /** + * Add handlers to be called when the Deferred object is resolved, rejected, or still in progress. + * + * @param doneFilter A function that is called when the Deferred is resolved. + * @param failFilter An optional function that is called when the Deferred is rejected. + * @param progressFilter An optional function that is called when progress notifications are sent to the Deferred. + */ + then(doneFilter: (...values: any[]) => U, failFilter?: (...reasons: any[]) => JQueryGenericPromise, progressFilter?: (...progression: any[]) => any): JQueryPromise; + /** + * Add handlers to be called when the Deferred object is resolved, rejected, or still in progress. + * + * @param doneFilter A function that is called when the Deferred is resolved. + * @param failFilter An optional function that is called when the Deferred is rejected. + * @param progressFilter An optional function that is called when progress notifications are sent to the Deferred. + */ + then(doneFilter: (...values: any[]) => JQueryGenericPromise, failFilter?: (...reasons: any[]) => JQueryGenericPromise, progressFilter?: (...progression: any[]) => any): JQueryPromise; } -/* - Interface for the JQuery deferred, part of callbacks -*/ +/** + * Interface for the JQuery deferred, part of callbacks + */ interface JQueryDeferred extends JQueryPromise { /** * Add handlers to be called when the Deferred object is either resolved or rejected.