Skip to content

Instantly share code, notes, and snippets.

@Morstis
Created April 20, 2021 10:39
Show Gist options
  • Save Morstis/c1963fd565d8b234871ae6662a11c8af to your computer and use it in GitHub Desktop.
Save Morstis/c1963fd565d8b234871ae6662a11c8af to your computer and use it in GitHub Desktop.
async loader
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