Skip to content

Instantly share code, notes, and snippets.

@voznik
Created September 16, 2019 14:52
Show Gist options
  • Select an option

  • Save voznik/1f31313a45d7dfc36765b8e8bd65b53a to your computer and use it in GitHub Desktop.

Select an option

Save voznik/1f31313a45d7dfc36765b8e8bd65b53a to your computer and use it in GitHub Desktop.
Angular Component "before destroy"
import { Component, Input, OnDestroy } from '@angular/core';
import { timer } from 'rxjs';
import { timeInterval, pluck, take} from 'rxjs/operators';
interface BeforeOnDestroy {
ngxBeforeOnDestroy();
}
type NgxInstance = BeforeOnDestroy & Object;
type Descriptor = TypedPropertyDescriptor<Function>;
type Key = string | symbol;
function BeforeOnDestroy(
target: NgxInstance,
key: Key,
descriptor: Descriptor
) {
return {
value: async function(...args: any[]) {
await target.ngxBeforeOnDestroy.apply(this);
return descriptor.value.apply(target, args);
},
};
}
@voznik
Copy link
Copy Markdown
Author

voznik commented Sep 16, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment