Guest User

Faulty @DestroyAware

a guest
Jun 21st, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. export function DestroyAware(destroyHookName: string = "ngOnDestroy"): Function {
  2.     return (target: Object, key: string): void => {
  3.         let originalDestroyHook: Function;
  4.         if (destroyHookName in target && target[destroyHookName] instanceof Function) {
  5.             originalDestroyHook = target[destroyHookName];
  6.         }
  7.  
  8.         Object.defineProperty(target, destroyHookName, {
  9.             value: function value(...args: any[]) {
  10.                 if (originalDestroyHook instanceof Function) {
  11.                     originalDestroyHook.apply(this, args);
  12.                 }
  13.                 this[key].next(true);
  14.                 this[key].complete();
  15.             }
  16.         });
  17.     };
  18. }
Advertisement
Add Comment
Please, Sign In to add comment