@@ -2,18 +2,23 @@ import 'proxy-state-tree'
22
33import {
44 Config as DefaultConfig ,
5+ ENVIRONMENT ,
56 EventType ,
67 IConfiguration ,
78 MODE_SSR ,
89 Overmind ,
9- OvermindMock
10+ OvermindMock ,
1011} from 'overmind'
1112import { IMutationCallback } from 'proxy-state-tree'
1213import * as react from 'react'
13- import { unstable_cancelCallback , unstable_getCurrentPriorityLevel , unstable_scheduleCallback } from 'scheduler'
14+ import {
15+ unstable_cancelCallback ,
16+ unstable_getCurrentPriorityLevel ,
17+ unstable_scheduleCallback ,
18+ } from 'scheduler'
1419
15- const IS_PRODUCTION = process . env . NODE_ENV === 'production'
16- const IS_TEST = process . env . NODE_ENV === 'test'
20+ const IS_PRODUCTION = ENVIRONMENT === 'production'
21+ const IS_TEST = ENVIRONMENT === 'test'
1722const isNode =
1823 ! IS_TEST && process && process . title && process . title . includes ( 'node' )
1924
@@ -40,12 +45,8 @@ function getFiberType(component) {
4045
4146// Inspired from https://github.com/facebook/react/blob/master/packages/react-devtools-shared/src/backend/renderer.js
4247function getDisplayName ( component ) : string {
43- const type = getFiberType ( component ) ;
44- return (
45- type . displayName ||
46- type . name ||
47- 'Anonymous'
48- ) ;
48+ const type = getFiberType ( component )
49+ return type . displayName || type . name || 'Anonymous'
4950}
5051
5152export interface IConnect < Config extends IConfiguration = DefaultConfig > {
@@ -75,19 +76,19 @@ export const Provider: react.ProviderExoticComponent<
7576> = context . Provider
7677
7778function useForceRerender ( ) {
78- const [ { flushId } , setTick ] = react . useState ( { tick : 0 , flushId : 0 } )
79+ const [ { flushId } , setTick ] = react . useState ( { tick : 0 , flushId : 0 } )
7980
8081 const forceRerender = react . useCallback ( ( flushId ?) => {
81- setTick ( current => ( {
82- ...current ,
83- tick : current . tick + 1 ,
84- flushId : flushId || current . flushId
85- } ) )
82+ setTick ( ( current ) => ( {
83+ ...current ,
84+ tick : current . tick + 1 ,
85+ flushId : flushId || current . flushId ,
86+ } ) )
8687 } , [ ] )
8788
8889 return {
8990 flushId,
90- forceRerender
91+ forceRerender,
9192 }
9293}
9394
@@ -103,7 +104,9 @@ const useCurrentComponent = () => {
103104 : { }
104105}
105106
106- const useState = < Config extends IConfiguration > ( ) : Overmind < Config > [ 'state' ] => {
107+ const useState = < Config extends IConfiguration > ( ) : Overmind <
108+ Config
109+ > [ 'state' ] => {
107110 const overmind = react . useContext ( context ) as Overmind < Config >
108111
109112 if ( ! ( overmind as any ) . mode ) {
@@ -116,22 +119,24 @@ const useState = <Config extends IConfiguration>(): Overmind<Config>['state'] =
116119
117120 const trackingRef = react . useRef < any > ( null )
118121
119- const { flushId, forceRerender} = useForceRerender ( )
122+ const { flushId, forceRerender } = useForceRerender ( )
120123
121124 if ( ! trackingRef . current ) {
122125 trackingRef . current = {
123126 tree : ( overmind as any ) . proxyStateTree . getTrackStateTree ( ) ,
124127 hasUpdatedBeforeCommit : false ,
125- stopTrackingTask : unstable_scheduleCallback ( unstable_getCurrentPriorityLevel ( ) , ( ) => {
126- trackingRef . current . tree . stopTracking ( )
127- } )
128+ stopTrackingTask : unstable_scheduleCallback (
129+ unstable_getCurrentPriorityLevel ( ) ,
130+ ( ) => {
131+ trackingRef . current . tree . stopTracking ( )
132+ }
133+ ) ,
128134 }
129135 }
130136
131137 if ( IS_PRODUCTION ) {
132138 react . useLayoutEffect ( ( ) => {
133139 trackingRef . current . mounted = true
134-
135140
136141 if ( trackingRef . current . hasUpdatedBeforeCommit ) {
137142 forceRerender ( )
@@ -217,7 +222,9 @@ const useState = <Config extends IConfiguration>(): Overmind<Config>['state'] =
217222 return trackingRef . current . tree . state
218223}
219224
220- const useActions = < Config extends IConfiguration > ( ) : Overmind < Config > [ 'actions' ] => {
225+ const useActions = < Config extends IConfiguration > ( ) : Overmind <
226+ Config
227+ > [ 'actions' ] => {
221228 const overmind = react . useContext ( context ) as Overmind < Config >
222229
223230 if ( ! ( overmind as any ) . mode ) {
@@ -227,7 +234,9 @@ const useActions = <Config extends IConfiguration>(): Overmind<Config>['actions
227234 return overmind . actions
228235}
229236
230- const useEffects = < Config extends IConfiguration > ( ) : Overmind < Config > [ 'effects' ] => {
237+ const useEffects = < Config extends IConfiguration > ( ) : Overmind <
238+ Config
239+ > [ 'effects' ] => {
231240 const overmind = react . useContext ( context ) as Overmind < Config >
232241
233242 if ( ! ( overmind as any ) . mode ) {
@@ -237,7 +246,9 @@ const useEffects = <Config extends IConfiguration>(): Overmind<Config>['effects
237246 return overmind . effects
238247}
239248
240- const useReaction = < Config extends IConfiguration > ( ) : Overmind < Config > [ 'reaction' ] => {
249+ const useReaction = < Config extends IConfiguration > ( ) : Overmind <
250+ Config
251+ > [ 'reaction' ] => {
241252 const overmind = react . useContext ( context ) as Overmind < Config >
242253
243254 if ( ! ( overmind as any ) . mode ) {
@@ -247,23 +258,33 @@ const useReaction = <Config extends IConfiguration>(): Overmind<Config>['reacti
247258 return overmind . reaction
248259}
249260
250- export const createStateHook : < Config extends IConfiguration = DefaultConfig > ( ) => ( ) => Overmind < Config > [ 'state' ] = ( ) => {
261+ export const createStateHook : <
262+ Config extends IConfiguration = DefaultConfig
263+ > ( ) => ( ) => Overmind < Config > [ 'state' ] = ( ) => {
251264 return useState as any
252265}
253266
254- export const createActionsHook : < Config extends IConfiguration = DefaultConfig > ( ) => ( ) => Overmind < Config > [ 'actions' ] = ( ) => {
267+ export const createActionsHook : <
268+ Config extends IConfiguration = DefaultConfig
269+ > ( ) => ( ) => Overmind < Config > [ 'actions' ] = ( ) => {
255270 return useActions as any
256271}
257272
258- export const createEffectsHook : < Config extends IConfiguration = DefaultConfig > ( ) => ( ) => Overmind < Config > [ 'effects' ] = ( ) => {
273+ export const createEffectsHook : <
274+ Config extends IConfiguration = DefaultConfig
275+ > ( ) => ( ) => Overmind < Config > [ 'effects' ] = ( ) => {
259276 return useEffects as any
260277}
261278
262- export const createReactionHook : < Config extends IConfiguration = DefaultConfig > ( ) => ( ) => Overmind < Config > [ 'reaction' ] = ( ) => {
279+ export const createReactionHook : <
280+ Config extends IConfiguration = DefaultConfig
281+ > ( ) => ( ) => Overmind < Config > [ 'reaction' ] = ( ) => {
263282 return useReaction as any
264283}
265284
266- export const createHook : < Config extends IConfiguration = DefaultConfig > ( ) => ( ) => {
285+ export const createHook : <
286+ Config extends IConfiguration = DefaultConfig
287+ > ( ) => ( ) => {
267288 state : Overmind < Config > [ 'state' ]
268289 actions : Overmind < Config > [ 'actions' ]
269290 effects : Overmind < Config > [ 'effects' ]
@@ -281,7 +302,7 @@ export const createHook: <Config extends IConfiguration = DefaultConfig>() => ()
281302 actions,
282303 effects,
283304 reaction : overmind . reaction ,
284- addMutationListener : overmind . addMutationListener
305+ addMutationListener : overmind . addMutationListener ,
285306 } as any
286307 }
287308}
@@ -307,11 +328,9 @@ export const createConnect: <
307328 keyof IConnect < Overmind < ThisConfig > >
308329 >
309330> = < Props , TComponent extends IReactComponent > ( ) => {
310- return (
311- component
312- ) => {
331+ return ( component ) => {
313332 let componentInstanceId = 0
314- const name = component . displayName || component . name || 'Anonymous' ;
333+ const name = component . displayName || component . name || 'Anonymous'
315334 const populatedComponent = component as any
316335 populatedComponent . __componentId =
317336 typeof populatedComponent . __componentId === 'undefined'
@@ -335,7 +354,7 @@ export const createConnect: <
335354 }
336355
337356 if ( IS_PRODUCTION ) {
338- class HOC extends react . Component < { innerRef : react . Ref < TComponent > } > {
357+ class HOC extends react . Component < { innerRef : react . Ref < TComponent > } > {
339358 tree : any
340359 overmind : any
341360 state : {
@@ -401,14 +420,16 @@ export const createConnect: <
401420 }
402421 }
403422
404- const refForwarder = react . forwardRef < TComponent , Props > ( ( props , ref ) => react . createElement ( HOC , {
405- ...props ,
406- innerRef : ref
407- } ) )
423+ const refForwarder = react . forwardRef < TComponent , Props > ( ( props , ref ) =>
424+ react . createElement ( HOC , {
425+ ...props ,
426+ innerRef : ref ,
427+ } )
428+ )
408429
409430 return refForwarder
410431 } else {
411- class HOC extends react . Component < { innerRef : react . Ref < TComponent > } > {
432+ class HOC extends react . Component < { innerRef : react . Ref < TComponent > } > {
412433 tree : any
413434 overmind : any
414435 componentInstanceId = componentInstanceId ++
@@ -504,10 +525,12 @@ export const createConnect: <
504525 }
505526 }
506527
507- const refForwarder = react . forwardRef < TComponent , Props > ( ( props , ref ) => react . createElement ( HOC , {
508- ...props ,
509- innerRef : ref
510- } ) )
528+ const refForwarder = react . forwardRef < TComponent , Props > ( ( props , ref ) =>
529+ react . createElement ( HOC , {
530+ ...props ,
531+ innerRef : ref ,
532+ } )
533+ )
511534
512535 Object . defineProperties ( refForwarder , {
513536 name : {
0 commit comments