Created
September 16, 2019 14:52
-
-
Save voznik/1f31313a45d7dfc36765b8e8bd65b53a to your computer and use it in GitHub Desktop.
Angular Component "before destroy"
This file contains hidden or 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 { 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); | |
| }, | |
| }; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
credits: angular/angular#20713 (comment)