refactor(all): make all method return a promise

This commit is contained in:
Manu Mtz.-Almeida
2018-08-28 18:16:10 +02:00
parent 5d32115684
commit 1d46973785
53 changed files with 307 additions and 442 deletions

View File

@ -162,15 +162,11 @@ export function autoFocus(containerEl: HTMLElement): HTMLElement | null {
return null;
}
export function eventMethod<T>(element: HTMLElement, eventName: string, callback?: (detail: T) => void): Promise<T> {
export function eventMethod<T>(element: HTMLElement, eventName: string): Promise<T> {
let resolve: (detail: T) => void;
const promise = new Promise<T>(r => resolve = r);
onceEvent(element, eventName, (event: any) => {
const detail = event.detail;
if (callback) {
callback(detail);
}
resolve(detail);
resolve(event.detail);
});
return promise;
}