1- import { EventType } from 'overmind'
1+ import { EventType , MODE_SSR } from 'overmind'
22
33const OVERMIND = Symbol ( 'OVERMIND' )
44const IS_PRODUCTION = process . env . NODE_ENV === 'production'
@@ -11,40 +11,63 @@ function createMixin(overmind, propsCallback) {
1111
1212 return {
1313 beforeMount ( this : any ) {
14- this [ OVERMIND ] = {
15- tree : ( overmind as any ) . proxyStateTree . getTrackStateTree ( ) ,
16- componentInstanceId : componentInstanceId ++ ,
17- onUpdate : ( mutations , paths , flushId ) => {
18- this [ OVERMIND ] . currentFlushId = flushId
19- this . $forceUpdate ( )
20- } ,
21- }
22- this . overmind = {
23- state : this [ OVERMIND ] . tree . state ,
24- actions : overmind . actions ,
25- effects : overmind . effects ,
26- addMutationListener : overmind . addMutationListener ,
27- }
14+ if ( overmind . mode === MODE_SSR ) {
15+ this . overmind = {
16+ state : overmind . state ,
17+ actions : overmind . actions ,
18+ effects : overmind . effects ,
19+ addMutationListener : overmind . addMutationListener ,
20+ }
21+ if ( propsCallback ) {
22+ Object . assign (
23+ this ,
24+ propsCallback ( {
25+ state : overmind . state ,
26+ actions : overmind . actions ,
27+ effects : overmind . effects ,
28+ } )
29+ )
30+ }
31+ } else {
32+ this [ OVERMIND ] = {
33+ tree : ( overmind as any ) . proxyStateTree . getTrackStateTree ( ) ,
34+ componentInstanceId : componentInstanceId ++ ,
35+ onUpdate : ( mutations , paths , flushId ) => {
36+ this [ OVERMIND ] . currentFlushId = flushId
37+ this . $forceUpdate ( )
38+ } ,
39+ }
40+ this . overmind = {
41+ state : this [ OVERMIND ] . tree . state ,
42+ actions : overmind . actions ,
43+ effects : overmind . effects ,
44+ addMutationListener : overmind . addMutationListener ,
45+ }
2846
29- if ( propsCallback ) {
30- Object . assign (
31- this ,
32- propsCallback ( {
33- state : this [ OVERMIND ] . tree . state ,
34- actions : overmind . actions ,
35- effects : overmind . effects ,
36- } )
37- )
47+ if ( propsCallback ) {
48+ Object . assign (
49+ this ,
50+ propsCallback ( {
51+ state : this [ OVERMIND ] . tree . state ,
52+ actions : overmind . actions ,
53+ effects : overmind . effects ,
54+ } )
55+ )
56+ }
57+ this [ OVERMIND ] . tree . track ( this [ OVERMIND ] . onUpdate )
3858 }
39- this [ OVERMIND ] . tree . track ( this [ OVERMIND ] . onUpdate )
4059 } ,
4160 beforeUpdate ( this : any ) {
61+ if ( overmind . mode === MODE_SSR ) return
62+
4263 this [ OVERMIND ] . tree . track ( this [ OVERMIND ] . onUpdate )
4364 } ,
4465 ...( IS_PRODUCTION
4566 ? null
4667 : {
4768 mounted ( this : any ) {
69+ if ( overmind . mode === MODE_SSR ) return
70+
4871 overmind . eventHub . emitAsync ( EventType . COMPONENT_ADD , {
4972 componentId,
5073 componentInstanceId : this [ OVERMIND ] . componentInstanceId ,
@@ -53,6 +76,8 @@ function createMixin(overmind, propsCallback) {
5376 } )
5477 } ,
5578 updated ( this : any ) {
79+ if ( overmind . mode === MODE_SSR ) return
80+
5681 overmind . eventHub . emitAsync ( EventType . COMPONENT_UPDATE , {
5782 componentId,
5883 componentInstanceId : this [ OVERMIND ] . componentInstanceId ,
@@ -63,6 +88,8 @@ function createMixin(overmind, propsCallback) {
6388 } ,
6489 } ) ,
6590 beforeDestroy ( this : any ) {
91+ if ( overmind . mode === MODE_SSR ) return
92+
6693 // @ts -ignore
6794 overmind . proxyStateTree . disposeTree ( this [ OVERMIND ] . tree )
6895 if ( IS_PRODUCTION ) {
0 commit comments