@@ -11,7 +11,7 @@ export type TConnect<Config extends Configuration> = {
1111}
1212
1313let nextComponentId = 0
14- /*
14+
1515export const createConnect = < A extends Overmind < any > > ( overmind : A ) => ( ) => {
1616 const componentId = nextComponentId ++
1717 let componentInstanceId = 0
@@ -24,14 +24,21 @@ export const createConnect = <A extends Overmind<any>>(overmind: A) => () => {
2424 const targetNgAfterViewChecked = target . prototype . ngAfterViewChecked
2525
2626 target . prototype . ngOnInit = function ( ) {
27+ const ngZ = new NgZone ( { enableLongStackTrace : false } )
28+
29+ this . __tree = overmind . proxyStateTree . getTrackingTree ( )
2730 this . overmind = {
28- state: overmind .state,
31+ state : this . __tree . state ,
2932 actions : overmind . actions ,
3033 }
34+ this . __shouldUpdatePaths = false
3135 this . __componentInstanceId = componentInstanceId ++
32- this.__tree = false
33- this.__currentTrackId = null
34- this.__listener = null
36+ this . __onUpdate = ( ) => {
37+ if ( this . cdr ) {
38+ this . cdr . markForCheck ( )
39+ }
40+ ngZ . run ( ( ) => { } )
41+ }
3542
3643 if ( targetNgOnInit ) {
3744 targetNgOnInit . apply ( target )
@@ -49,46 +56,29 @@ export const createConnect = <A extends Overmind<any>>(overmind: A) => () => {
4956 }
5057
5158 target . prototype . ngAfterContentInit = function ( ) {
52- this.__currentTrackId = overmind.trackState( )
59+ this . __tree . track ( this . __onUpdate )
5360
5461 if ( targetNgAfterContentInit ) {
5562 targetNgAfterContentInit . apply ( target )
5663 }
5764 }
5865
5966 target . prototype . ngAfterViewInit = function ( ) {
60- const ngZ = new NgZone({ enableLongStackTrace: false })
61- const paths = overmind.clearTrackState(this.__currentTrackId)
62-
6367 overmind . eventHub . emitAsync ( EventType . COMPONENT_ADD , {
6468 componentId,
6569 componentInstanceId : this . __componentInstanceId ,
6670 name : this . constructor . name || '' ,
67- paths: Array.from(paths ),
71+ paths : Array . from ( this . __tree . pathDependencies ) ,
6872 } )
69- this.__listener = overmind.addFlushListener(paths, (flushId) => {
70- this.__shouldUpdatePaths = true
71- if (this.cdr) {
72- this.cdr.markForCheck()
73- }
74- ngZ.run(() => {})
7573
76- overmind.eventHub.emitAsync(EventType.COMPONENT_UPDATE, {
77- componentId,
78- componentInstanceId: this.__componentInstanceId,
79- name: this.constructor.name || '',
80- paths: Array.from(paths),
81- flushId,
82- })
83- })
8474 if ( targetNgAfterViewInit ) {
8575 targetNgAfterViewInit . apply ( target )
8676 }
8777 }
8878
8979 target . prototype . ngDoCheck = function ( ) {
9080 if ( this . __shouldUpdatePaths ) {
91- this.__currentTrackId = overmind.trackState( )
81+ this . __tree . track ( this . __onUpdate )
9282 }
9383 if ( targetNgDoCheck ) {
9484 targetNgDoCheck . apply ( target )
@@ -97,14 +87,13 @@ export const createConnect = <A extends Overmind<any>>(overmind: A) => () => {
9787
9888 target . prototype . ngAfterViewChecked = function ( ) {
9989 if ( this . __shouldUpdatePaths ) {
100- const paths = overmind.clearTrackState(this.__currentTrackId)
101- this.__listener.update(paths)
10290 this . __shouldUpdatePaths = false
10391 overmind . eventHub . emitAsync ( EventType . COMPONENT_UPDATE , {
10492 componentId,
10593 componentInstanceId : this . __componentInstanceId ,
10694 name : this . constructor . name || '' ,
107- paths: Array.from(paths),
95+ paths : Array . from ( this . __tree . pathDependencies ) ,
96+ flushId,
10897 } )
10998 }
11099 if ( targetNgAfterViewChecked ) {
@@ -123,10 +112,9 @@ export const createConnect = <A extends Overmind<any>>(overmind: A) => () => {
123112 componentInstanceId : this . __componentInstanceId ,
124113 name : this . constructor . name || '' ,
125114 } )
126- this.__listener.dispose( )
115+ overmind . proxyStateTree . disposeTree ( this . __tree )
127116 }
128117
129118 return target
130119 }
131120}
132- */
0 commit comments