From d6fa7eb79f413fb318cc2f648c4219642fbe51d3 Mon Sep 17 00:00:00 2001 From: Manish Lakhara Date: Sat, 30 Jul 2016 03:11:17 +0530 Subject: [PATCH] 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 {