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.
This commit is contained in:
Manish Lakhara
2016-07-30 03:11:17 +05:30
committed by GitHub
parent 46ed88240c
commit d6fa7eb79f

53
hellojs/hellojs.d.ts vendored
View File

@@ -35,10 +35,49 @@ interface HelloJSEventArgument {
authResponse?: any;
}
interface HelloJSImmediateSuccessCB<T, TP> {
(value: T): TP;
}
interface HelloJSImmediateErrorCB<TP> {
(err: any): TP;
}
interface HelloJSDeferredSuccessCB<T, TP> {
(value: T): HelloJSThenable<TP>;
}
interface HelloJSDeferredErrorCB<TP> {
(error: any): HelloJSThenable<TP>;
}
interface HelloJSThenable<T> {
then<TP>(
successCB?: HelloJSDeferredSuccessCB<T, TP>,
errorCB?: HelloJSDeferredErrorCB<TP>
): HelloJSThenable<TP>;
then<TP>(
successCB?: HelloJSDeferredSuccessCB<T, TP>,
errorCB?: HelloJSImmediateErrorCB<TP>
): HelloJSThenable<TP>;
then<TP>(
successCB?: HelloJSImmediateSuccessCB<T, TP>,
errorCB?: HelloJSDeferredErrorCB<TP>
): HelloJSThenable<TP>;
then<TP>(
successCB?: HelloJSImmediateSuccessCB<T, TP>,
errorCB?: HelloJSImmediateErrorCB<TP>
): HelloJSThenable<TP>;
}
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 {