@@ -4,6 +4,7 @@ import { Overmind, EventType } from 'overmind'
44import { BehaviorSubject , Observable } from 'rxjs'
55import { map } from 'rxjs/operators'
66
7+ // @ts -ignore
78const IS_PRODUCTION = process . env . NODE_ENV === 'production'
89
910let nextComponentId = 0
@@ -20,16 +21,16 @@ export const Track = (Component) => {
2021 return Object . keys ( target ) . find ( ( key ) => target [ key ] instanceof Service )
2122 }
2223
23- const targetNgOnInit = Component . prototype . ngOnInit
24- Component . prototype . ngOnInit = function ( ) {
24+ const targetNgAfterViewInit = Component . prototype . ngAfterViewInit
25+ Component . prototype . ngAfterViewInit = function ( ) {
2526 const service = this [ findService ( this ) ]
2627 service . addComponent ( {
2728 componentId,
2829 componentInstanceId : componentInstanceId ++ ,
2930 name : Component . name ,
3031 } )
3132
32- targetNgOnInit && targetNgOnInit . call ( this )
33+ targetNgAfterViewInit && targetNgAfterViewInit . call ( this )
3334 }
3435}
3536
@@ -67,12 +68,14 @@ export class Service<App extends Overmind<any>> {
6768 this . tree . track ( this . onUpdate )
6869 this . subject . next ( this . tree . state )
6970 if ( this . componentDetails ) {
70- this . overmind . eventHub . emitAsync ( EventType . COMPONENT_UPDATE , {
71- componentId : this . componentDetails . componentId ,
72- componentInstanceId : this . componentDetails . componentInstanceId ,
73- name : this . componentDetails . name ,
74- paths : Array . from ( this . tree . pathDependencies ) as any ,
75- flushId,
71+ ; ( window [ '__zone_symbol__setTimeout' ] || setTimeout ) ( ( ) => {
72+ this . overmind . eventHub . emitAsync ( EventType . COMPONENT_UPDATE , {
73+ componentId : this . componentDetails . componentId ,
74+ componentInstanceId : this . componentDetails . componentInstanceId ,
75+ name : this . componentDetails . name ,
76+ paths : Array . from ( this . tree . pathDependencies ) as any ,
77+ flushId,
78+ } )
7679 } )
7780 }
7881 }
0 commit comments