@@ -19,6 +19,8 @@ import {
1919} from './internalTypes'
2020import Reaction from './reaction'
2121
22+ export { modules } from './modules'
23+
2224export { IValueAction , Compose , EventType }
2325
2426export const log = ( ...objects : any [ ] ) =>
@@ -37,15 +39,6 @@ export type Configuration = {
3739 effects ?: any
3840 actions ?: any
3941 reactions ?: any
40- modules ?: {
41- [ namespace : string ] : {
42- onInitialize ?: any
43- state ?: any
44- effects ?: any
45- actions ?: any
46- reactions ?: any
47- }
48- }
4942}
5043
5144/*
@@ -67,43 +60,9 @@ type StateNode<State extends object> = {
6760 : State [ P ] extends object ? StateNode < State [ P ] > : State [ P ]
6861}
6962
70- export type TState < Config extends Configuration > = [ Config [ 'state' ] ] extends [
71- undefined
72- ]
73- ? {
74- [ P in keyof SubType < Config [ 'modules' ] , { state : { } } > ] : SubType <
75- Config [ 'modules' ] ,
76- { state : { } }
77- > [ P ] [ 'state' ]
78- }
79- : [ Config [ 'modules' ] ] extends [ undefined ]
80- ? Config [ 'state' ]
81- : Config [ 'state' ] &
82- {
83- [ P in keyof SubType < Config [ 'modules' ] , { state : { } } > ] : SubType <
84- Config [ 'modules' ] ,
85- { state : { } }
86- > [ P ] [ 'state' ]
87- }
63+ export type TState < Config extends Configuration > = Config [ 'state' ]
8864
89- export type TEffects < Config extends Configuration > = [
90- Config [ 'effects' ]
91- ] extends [ undefined ]
92- ? {
93- [ P in keyof SubType < Config [ 'modules' ] , { effects : object } > ] : SubType <
94- Config [ 'modules' ] ,
95- { effects : object }
96- > [ P ] [ 'effects' ]
97- }
98- : [ Config [ 'modules' ] ] extends [ undefined ]
99- ? Config [ 'effects' ]
100- : Config [ 'effects' ] &
101- {
102- [ P in keyof SubType < Config [ 'modules' ] , { effects : object } > ] : SubType <
103- Config [ 'modules' ] ,
104- { effects : object }
105- > [ P ] [ 'effects' ]
106- }
65+ export type TEffects < Config extends Configuration > = Config [ 'effects' ]
10766
10867export type Mutate < Value = any > = ( state : IApp [ 'state' ] , value : Value ) => void
10968
@@ -131,8 +90,8 @@ export type Action<InitialValue = void, ReturnValue = any> = Compose<
13190
13291export type TAction <
13392 InitialValue ,
134- ReturnValue ,
135- App extends { state : any ; effects : any }
93+ ReturnValue = InitialValue ,
94+ App extends { state : any ; effects : any } = { state : any ; effects : any }
13695> = Compose <
13796 App [ 'state' ] ,
13897 App [ 'effects' ] & { state : App [ 'state' ] } ,
@@ -172,56 +131,10 @@ export type Compute<Input, Output> = (
172131) => ( state : IApp [ 'state' ] ) => Output
173132
174133export type TConfig < Config extends Configuration > = {
175- state : [ Config [ 'state' ] ] extends [ undefined ]
176- ? {
177- [ P in keyof SubType < Config [ 'modules' ] , { state : { } } > ] : SubType <
178- Config [ 'modules' ] ,
179- { state : { } }
180- > [ P ] [ 'state' ]
181- }
182- : [ Config [ 'modules' ] ] extends [ undefined ]
183- ? Config [ 'state' ]
184- : Config [ 'state' ] &
185- {
186- [ P in keyof SubType < Config [ 'modules' ] , { state : { } } > ] : SubType <
187- Config [ 'modules' ] ,
188- { state : { } }
189- > [ P ] [ 'state' ]
190- }
191- effects : [ Config [ 'effects' ] ] extends [ undefined ]
192- ? {
193- [ P in keyof SubType < Config [ 'modules' ] , { effects : object } > ] : SubType <
194- Config [ 'modules' ] ,
195- { effects : object }
196- > [ P ] [ 'effects' ]
197- }
198- : [ Config [ 'modules' ] ] extends [ undefined ]
199- ? Config [ 'effects' ]
200- : Config [ 'effects' ] &
201- {
202- [ P in keyof SubType <
203- Config [ 'modules' ] ,
204- { effects : object }
205- > ] : SubType < Config [ 'modules' ] , { effects : object } > [ P ] [ 'effects' ]
206- }
207- actions : [ Config [ 'actions' ] ] extends [ undefined ]
208- ? {
209- [ P in keyof SubType < Config [ 'modules' ] , { actions : object } > ] : SubType <
210- Config [ 'modules' ] ,
211- { actions : object }
212- > [ P ] [ 'actions' ]
213- }
214- : [ Config [ 'modules' ] ] extends [ undefined ]
215- ? Config [ 'actions' ]
216- : Config [ 'actions' ] &
217- {
218- [ P in keyof SubType <
219- Config [ 'modules' ] ,
220- { actions : object }
221- > ] : SubType < Config [ 'modules' ] , { actions : object } > [ P ] [ 'actions' ]
222- }
134+ state : Config [ 'state' ] & { }
135+ effects : Config [ 'effects' ] & { }
136+ actions : Config [ 'actions' ] & { }
223137 reactions : any
224- namespaces : any
225138}
226139
227140export type TActionCreator < App > = {
@@ -268,10 +181,6 @@ export default class App<
268181 }
269182 }
270183
271- /*
272- Mutate module functions into module objects
273- */
274- this . mutateModuleFunctionsIntoModules ( configuration )
275184 /*
276185 Set up an eventHub to trigger information from derived, computed and reactions
277186 */
@@ -352,36 +261,11 @@ export default class App<
352261 this . proxyStateTree = proxyStateTree
353262 this . eventHub = eventHub
354263
355- const initializers = this . getInitializers ( configuration )
356-
357- if ( ! initializers . length ) {
358- return
359- }
360-
361- const rootInitializer =
362- initializers [ 0 ] . name === 'onInitialize' ? initializers . shift ( ) : null
363-
364- let onInitialize
365-
366- if ( initializers . length ) {
367- onInitialize = operators . parallel ( initializers )
368- }
369-
370- if ( rootInitializer ) {
371- onInitialize = operators . compose ( rootInitializer )
372- }
373-
374- // @ts -ignore
375- onInitialize . displayName = 'onInitialize'
376- onInitialize ( undefined )
377- }
378- private mutateModuleFunctionsIntoModules ( config : Configuration ) {
379- if ( config . modules ) {
380- Object . keys ( config . modules ) . forEach ( ( key ) => {
381- if ( typeof config . modules [ key ] === 'function' ) {
382- config . modules [ key ] = ( config . modules [ key ] as any ) ( key )
383- }
384- } )
264+ if ( configuration . onInitialize ) {
265+ const onInitialize = operators . compose ( configuration . onInitialize )
266+ // @ts -ignore
267+ onInitialize . displayName = 'onInitialize'
268+ onInitialize ( undefined )
385269 }
386270 }
387271 private initializeDevtools ( host , actionChain , eventHub , proxyStateTree ) {
@@ -492,44 +376,14 @@ export default class App<
492376 reaction . create ( reactions [ name ] [ 0 ] , reactions [ name ] [ 1 ] )
493377 } )
494378 }
495- private getState ( configuration ) {
379+ private getState ( configuration : Configuration ) {
496380 let state = { }
497381 if ( configuration . state ) {
498382 state = this . processState ( configuration . state )
499383 }
500- if ( configuration . modules ) {
501- Object . keys ( configuration . modules ) . reduce ( ( aggr , key ) => {
502- if ( configuration . modules [ key ] . state ) {
503- return Object . assign ( aggr , {
504- [ key ] : this . processState ( configuration . modules [ key ] . state ) ,
505- } )
506- }
507-
508- return aggr
509- } , state )
510- }
511384
512385 return state
513386 }
514- private getInitializers ( configuration ) {
515- let initializers = [ ]
516- if ( configuration . onInitialize ) {
517- initializers . push ( configuration . onInitialize )
518- }
519- if ( configuration . modules ) {
520- initializers = Object . keys ( configuration . modules ) . reduce ( ( aggr , key ) => {
521- if ( configuration . modules [ key ] . onInitialize ) {
522- configuration . modules [ key ] . onInitialize . displayName =
523- key + '.onInitialize'
524- return aggr . concat ( configuration . modules [ key ] . onInitialize )
525- }
526-
527- return aggr
528- } , initializers )
529- }
530-
531- return initializers
532- }
533387 private processState ( state : { } ) {
534388 return Object . keys ( state ) . reduce ( ( aggr , key ) => {
535389 const value = state [ key ]
@@ -544,22 +398,11 @@ export default class App<
544398 return aggr
545399 } , { } )
546400 }
547- private getActions ( configuration , operators ) {
401+ private getActions ( configuration : Configuration , operators ) {
548402 let actions = { }
549403 if ( configuration . actions ) {
550404 actions = configuration . actions
551405 }
552- if ( configuration . modules ) {
553- Object . keys ( configuration . modules ) . reduce ( ( aggr , key ) => {
554- if ( configuration . modules [ key ] . actions ) {
555- return Object . assign ( aggr , {
556- [ key ] : configuration . modules [ key ] . actions ,
557- } )
558- }
559-
560- return aggr
561- } , actions )
562- }
563406
564407 const evaluatedActions = Object . keys ( actions ) . reduce ( ( aggr , name ) => {
565408 if ( typeof actions [ name ] === 'function' ) {
0 commit comments