From ee580ff30389949110cdf192ada091e244355540 Mon Sep 17 00:00:00 2001 From: John Reilly Date: Mon, 17 Mar 2014 15:26:53 +0000 Subject: [PATCH] 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 81600af7f..7e6c79cb3 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.