From d6fa7eb79f413fb318cc2f648c4219642fbe51d3 Mon Sep 17 00:00:00 2001 From: Manish Lakhara Date: Sat, 30 Jul 2016 03:11:17 +0530 Subject: [PATCH 1/4] Added Thenable interface for Async Methods. According to HelloJs doc, async methods return Promise A+ compliant thenable. So added interface for thenable and changed return type of login, logout and api methods. --- hellojs/hellojs.d.ts | 53 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/hellojs/hellojs.d.ts b/hellojs/hellojs.d.ts index 686d5c1adf..64e7372a08 100644 --- a/hellojs/hellojs.d.ts +++ b/hellojs/hellojs.d.ts @@ -35,10 +35,49 @@ interface HelloJSEventArgument { authResponse?: any; } +interface HelloJSImmediateSuccessCB { + (value: T): TP; +} + +interface HelloJSImmediateErrorCB { + (err: any): TP; +} + +interface HelloJSDeferredSuccessCB { + (value: T): HelloJSThenable; +} + +interface HelloJSDeferredErrorCB { + (error: any): HelloJSThenable; +} + +interface HelloJSThenable { + then( + successCB?: HelloJSDeferredSuccessCB, + errorCB?: HelloJSDeferredErrorCB + ): HelloJSThenable; + + then( + successCB?: HelloJSDeferredSuccessCB, + errorCB?: HelloJSImmediateErrorCB + ): HelloJSThenable; + + then( + successCB?: HelloJSImmediateSuccessCB, + errorCB?: HelloJSDeferredErrorCB + ): HelloJSThenable; + + then( + successCB?: HelloJSImmediateSuccessCB, + errorCB?: HelloJSImmediateErrorCB + ): HelloJSThenable; +} + + interface HelloJSStatic extends HelloJSEvent { init(serviceAppIds: { [id: string]: string; }, options?: HelloJSLoginOptions): void; - login(network: string, options?: HelloJSLoginOptions, callback?: () => void): void; - logout(network: string, options?: HelloJSLogoutOptions, callback?: () => void): void; + login(network: string, options?: HelloJSLoginOptions, callback?: () => void): HelloJSThenable; + logout(network: string, options?: HelloJSLogoutOptions, callback?: () => void): HelloJSThenable; getAuthResponse(network: string): any; service(network: string): HelloJSServiceDef; settings: HelloJSLoginOptions; @@ -46,11 +85,15 @@ interface HelloJSStatic extends HelloJSEvent { init(servicesDef: { [id: string]: HelloJSServiceDef; }): void; } + + + + interface HelloJSStaticNamed { - login(option?: HelloJSLoginOptions, callback?: () => void): void; - logout(callback?: () => void): void; + login(option?: HelloJSLoginOptions, callback?: () => void): HelloJSThenable; + logout(callback?: () => void): HelloJSThenable; getAuthResponse(): any; - api(path?: string, method?: string, data?: any, callback?: (json?: any) => void): HelloJSStatic; + api(path?: string, method?: string, data?: any, callback?: (json?: any) => void): HelloJSThenable; } interface HelloJSOAuthDef { From 3e722697c85ac46a9b262447806b91247185c6a1 Mon Sep 17 00:00:00 2001 From: Manish Lakhara Date: Sat, 30 Jul 2016 03:27:03 +0530 Subject: [PATCH 2/4] Fix: HelloJSThenable required a type parameter. --- hellojs/hellojs.d.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hellojs/hellojs.d.ts b/hellojs/hellojs.d.ts index 64e7372a08..7dabae4054 100644 --- a/hellojs/hellojs.d.ts +++ b/hellojs/hellojs.d.ts @@ -76,8 +76,8 @@ interface HelloJSThenable { interface HelloJSStatic extends HelloJSEvent { init(serviceAppIds: { [id: string]: string; }, options?: HelloJSLoginOptions): void; - login(network: string, options?: HelloJSLoginOptions, callback?: () => void): HelloJSThenable; - logout(network: string, options?: HelloJSLogoutOptions, callback?: () => void): HelloJSThenable; + login(network: string, options?: HelloJSLoginOptions, callback?: () => void): HelloJSThenable; + logout(network: string, options?: HelloJSLogoutOptions, callback?: () => void): HelloJSThenable; getAuthResponse(network: string): any; service(network: string): HelloJSServiceDef; settings: HelloJSLoginOptions; @@ -90,10 +90,10 @@ interface HelloJSStatic extends HelloJSEvent { interface HelloJSStaticNamed { - login(option?: HelloJSLoginOptions, callback?: () => void): HelloJSThenable; - logout(callback?: () => void): HelloJSThenable; + login(option?: HelloJSLoginOptions, callback?: () => void): HelloJSThenable; + logout(callback?: () => void): HelloJSThenable; getAuthResponse(): any; - api(path?: string, method?: string, data?: any, callback?: (json?: any) => void): HelloJSThenable; + api(path?: string, method?: string, data?: any, callback?: (json?: any) => void): HelloJSThenable; } interface HelloJSOAuthDef { From 406a22a9c1ed920e23f0b4ad6069810962479885 Mon Sep 17 00:00:00 2001 From: Manish Lakhara Date: Sat, 30 Jul 2016 03:49:59 +0530 Subject: [PATCH 3/4] Implemented a simpler then interface as generic typings was not needed --- hellojs/hellojs.d.ts | 59 +++++++++----------------------------------- 1 file changed, 11 insertions(+), 48 deletions(-) diff --git a/hellojs/hellojs.d.ts b/hellojs/hellojs.d.ts index 7dabae4054..d54bca2905 100644 --- a/hellojs/hellojs.d.ts +++ b/hellojs/hellojs.d.ts @@ -27,57 +27,24 @@ interface HelloJSEvent { success(callback: (json?: any) => void): HelloJSStatic; error(callback: (json?: any) => void): HelloJSStatic; complete(callback: (json?: any) => void): HelloJSStatic; + then(successCallback: (json?: any) => void, errorCallback: (json?: any) => void): HelloJSStatic; } +interface HelloJSThenable { + then(successCallback: (json?: any) => void, errorCallback: (json?: any) => void): HelloJSStatic; +} + + interface HelloJSEventArgument { network: string; authResponse?: any; } -interface HelloJSImmediateSuccessCB { - (value: T): TP; -} - -interface HelloJSImmediateErrorCB { - (err: any): TP; -} - -interface HelloJSDeferredSuccessCB { - (value: T): HelloJSThenable; -} - -interface HelloJSDeferredErrorCB { - (error: any): HelloJSThenable; -} - -interface HelloJSThenable { - then( - successCB?: HelloJSDeferredSuccessCB, - errorCB?: HelloJSDeferredErrorCB - ): HelloJSThenable; - - then( - successCB?: HelloJSDeferredSuccessCB, - errorCB?: HelloJSImmediateErrorCB - ): HelloJSThenable; - - then( - successCB?: HelloJSImmediateSuccessCB, - errorCB?: HelloJSDeferredErrorCB - ): HelloJSThenable; - - then( - successCB?: HelloJSImmediateSuccessCB, - errorCB?: HelloJSImmediateErrorCB - ): HelloJSThenable; -} - - interface HelloJSStatic extends HelloJSEvent { init(serviceAppIds: { [id: string]: string; }, options?: HelloJSLoginOptions): void; - login(network: string, options?: HelloJSLoginOptions, callback?: () => void): HelloJSThenable; - logout(network: string, options?: HelloJSLogoutOptions, callback?: () => void): HelloJSThenable; + login(network: string, options?: HelloJSLoginOptions, callback?: () => void): HelloJSThenable; + logout(network: string, options?: HelloJSLogoutOptions, callback?: () => void): HelloJSThenable; getAuthResponse(network: string): any; service(network: string): HelloJSServiceDef; settings: HelloJSLoginOptions; @@ -85,15 +52,11 @@ interface HelloJSStatic extends HelloJSEvent { init(servicesDef: { [id: string]: HelloJSServiceDef; }): void; } - - - - interface HelloJSStaticNamed { - login(option?: HelloJSLoginOptions, callback?: () => void): HelloJSThenable; - logout(callback?: () => void): HelloJSThenable; + login(option?: HelloJSLoginOptions, callback?: () => void): void; + logout(callback?: () => void): void; getAuthResponse(): any; - api(path?: string, method?: string, data?: any, callback?: (json?: any) => void): HelloJSThenable; + api(path?: string, method?: string, data?: any, callback?: (json?: any) => void): HelloJSStatic; } interface HelloJSOAuthDef { From 951b738dc935be4b5f31bcb92f7dfc3f863fa3d5 Mon Sep 17 00:00:00 2001 From: Manish Lakhara Date: Sat, 6 Aug 2016 21:15:34 +0530 Subject: [PATCH 4/4] Added Promise/A+ compliant thenable. Extending HelloJSEvent from HelloJSThenable. --- hellojs/hellojs.d.ts | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/hellojs/hellojs.d.ts b/hellojs/hellojs.d.ts index 7dabae4054..d831a3d836 100644 --- a/hellojs/hellojs.d.ts +++ b/hellojs/hellojs.d.ts @@ -18,23 +18,6 @@ interface HelloJSLogoutOptions { force?: boolean; } -interface HelloJSEvent { - on(event: string, callback: (auth: HelloJSEventArgument) => void): HelloJSStatic; - off(event: string, callback: (auth: HelloJSEventArgument) => void): HelloJSStatic; - findEvents(event: string, callback: (name: string, index: number) => void): void; - emit(event: string, data: any): HelloJSStatic; - emitAfter(): HelloJSStatic; - success(callback: (json?: any) => void): HelloJSStatic; - error(callback: (json?: any) => void): HelloJSStatic; - complete(callback: (json?: any) => void): HelloJSStatic; -} - - -interface HelloJSEventArgument { - network: string; - authResponse?: any; -} - interface HelloJSImmediateSuccessCB { (value: T): TP; } @@ -73,11 +56,28 @@ interface HelloJSThenable { ): HelloJSThenable; } +interface HelloJSEvent extends HelloJSThenable { + on(event: string, callback: (auth: HelloJSEventArgument) => void): HelloJSStatic; + off(event: string, callback: (auth: HelloJSEventArgument) => void): HelloJSStatic; + findEvents(event: string, callback: (name: string, index: number) => void): void; + emit(event: string, data: any): HelloJSStatic; + emitAfter(): HelloJSStatic; + success(callback: (json?: any) => void): HelloJSStatic; + error(callback: (json?: any) => void): HelloJSStatic; + complete(callback: (json?: any) => void): HelloJSStatic; +} + + +interface HelloJSEventArgument { + network: string; + authResponse?: any; +} + interface HelloJSStatic extends HelloJSEvent { init(serviceAppIds: { [id: string]: string; }, options?: HelloJSLoginOptions): void; - login(network: string, options?: HelloJSLoginOptions, callback?: () => void): HelloJSThenable; - logout(network: string, options?: HelloJSLogoutOptions, callback?: () => void): HelloJSThenable; + login(network: string, options?: HelloJSLoginOptions, callback?: () => void): HelloJSStatic; + logout(network: string, options?: HelloJSLogoutOptions, callback?: () => void): HelloJSStatic; getAuthResponse(network: string): any; service(network: string): HelloJSServiceDef; settings: HelloJSLoginOptions; @@ -93,7 +93,7 @@ interface HelloJSStaticNamed { login(option?: HelloJSLoginOptions, callback?: () => void): HelloJSThenable; logout(callback?: () => void): HelloJSThenable; getAuthResponse(): any; - api(path?: string, method?: string, data?: any, callback?: (json?: any) => void): HelloJSThenable; + api(path?: string, method?: string, data?: any, callback?: (json?: any) => void): HelloJSStatic; } interface HelloJSOAuthDef {