Created
April 20, 2021 10:39
-
-
Save Morstis/c1963fd565d8b234871ae6662a11c8af to your computer and use it in GitHub Desktop.
async loader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { LoaderFactory } from '../services/loaderFactory.service'; | |
/** | |
* - Startet beim Aufruf der Methode die loading Animation. | |
* - Stoppt die Animation, wenn der Promise erfüllt wird. | |
*/ | |
export const asyncLoader = () => { | |
return (target: any, propertyKey: string, descriptor: PropertyDescriptor) => { | |
const originalMethod: Function = descriptor.value; | |
descriptor.value = function (...args: any[]) { | |
const result: Promise<any> = originalMethod.apply(this, args); | |
LoaderFactory.getService().isLoading.next(true); | |
result.finally(() => LoaderFactory.getService().isLoading.next(false)); | |
return result; | |
}; | |
return descriptor; | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment