Skip to content

Instantly share code, notes, and snippets.

@chaosmonster
Created February 8, 2019 12:36
Show Gist options
  • Save chaosmonster/adda1c0eed467fd6cd760408245ff60e to your computer and use it in GitHub Desktop.
Save chaosmonster/adda1c0eed467fd6cd760408245ff60e to your computer and use it in GitHub Desktop.
export const onInit = <T extends Constructor>(base: T = class {} as T) =>
class OnInitSubject extends base implements OnInit, AfterViewInit {
private _init = new BehaviorSubject<void>(null);
onInit$ = this._init.asObservable();
ngOnInit(): void {
this._init.next();
// tslint:disable-next-line:no-unused-expression
super['ngOnInit'] && super['ngOnInit']();
}
ngAfterViewInit(): void {
this._init.complete();
// tslint:disable-next-line:no-unused-expression
super['ngAfterViewInit'] && super['ngAfterViewInit']();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment