@@ -186,7 +186,7 @@ interface NamespacedConfiguration {
186186}
187187
188188function parseNamespacedConfig (
189- result : { actions : any ; effects : any ; state : any ; initializers : any [ ] } ,
189+ result : { actions : any ; effects : any ; state : any ; initializers : any } ,
190190 name : string ,
191191 config : IConfiguration
192192) {
@@ -202,7 +202,7 @@ function parseNamespacedConfig(
202202 result . state [ name ] = state
203203 }
204204 if ( onInitialize ) {
205- result . initializers . push ( onInitialize )
205+ result . initializers [ name ] = onInitialize
206206 }
207207}
208208
@@ -215,7 +215,7 @@ export function namespaced<T extends NamespacedConfiguration>(
215215 actions : SubType < { [ P in keyof T ] : T [ P ] [ 'actions' ] } , object >
216216} {
217217 const result : any = {
218- initializers : [ ] ,
218+ initializers : { } ,
219219 actions : { } ,
220220 effects : { } ,
221221 state : { } ,
@@ -225,19 +225,26 @@ export function namespaced<T extends NamespacedConfiguration>(
225225 parseNamespacedConfig ( result , name , namespaces [ name ] )
226226 } )
227227
228- return Object . assign (
229- {
230- actions : result . actions ,
231- effects : result . effects ,
232- state : result . state ,
233- } ,
234- result . initializers . length
235- ? {
236- onInitialize : ( context , app ) =>
237- Promise . all ( result . initializers . map ( ( cb ) => cb ( context , app ) ) ) ,
238- }
239- : { }
240- )
228+ return Object . assign ( {
229+ actions : result . actions ,
230+ effects : result . effects ,
231+ state : result . state ,
232+ onInitialize : ( context , app ) =>
233+ Promise . all (
234+ Object . keys ( result . initializers ) . map ( ( key ) =>
235+ result . initializers [ key ] (
236+ {
237+ ...context ,
238+ execution : {
239+ ...context . execution ,
240+ namespacePath : context . execution . namespacePath . concat ( key ) ,
241+ } ,
242+ } ,
243+ app
244+ )
245+ )
246+ ) ,
247+ } )
241248}
242249
243250interface LazyConfiguration {
0 commit comments