2
2
/** */
3
3
import { NgModuleRef , Injector , NgModuleFactory , Type , Compiler , NgModuleFactoryLoader } from "@angular/core" ;
4
4
import {
5
- Transition , LazyLoadResult , UIRouter , Resolvable , NATIVE_INJECTOR_TOKEN , isString , unnestR , inArray
5
+ Transition , LazyLoadResult , UIRouter , Resolvable , NATIVE_INJECTOR_TOKEN , isString , unnestR , inArray , StateObject ,
6
+ uniqR
6
7
} from "ui-router-core" ;
7
- import { RootModule , UIROUTER_ROOT_MODULE , UIROUTER_MODULE_TOKEN } from "../uiRouterNgModule" ;
8
+ import { RootModule , UIROUTER_ROOT_MODULE , UIROUTER_MODULE_TOKEN , StatesModule } from "../uiRouterNgModule" ;
8
9
import { applyModuleConfig } from "../uiRouterConfig" ;
9
10
10
11
/**
@@ -143,14 +144,20 @@ export function applyNgModule(transition: Transition, ng2Module: NgModuleRef<any
143
144
// Final name (without the .**)
144
145
let replacementName = isFuture && isFuture [ 1 ] ;
145
146
146
- let newRootModules : RootModule [ ] = multiProviderParentChildDelta ( parentInjector , injector , UIROUTER_ROOT_MODULE ) ;
147
+ let newRootModules = multiProviderParentChildDelta ( parentInjector , injector , UIROUTER_ROOT_MODULE )
148
+ . reduce ( uniqR , [ ] ) as RootModule [ ] ;
149
+ let newChildModules = multiProviderParentChildDelta ( parentInjector , injector , UIROUTER_MODULE_TOKEN )
150
+ . reduce ( uniqR , [ ] ) as StatesModule [ ] ;
151
+
147
152
if ( newRootModules . length ) {
148
153
console . log ( newRootModules ) ;
149
154
throw new Error ( 'Lazy loaded modules should not contain a UIRouterModule.forRoot() module' ) ;
150
155
}
151
156
152
- let newChildModules : RootModule [ ] = multiProviderParentChildDelta ( parentInjector , injector , UIROUTER_MODULE_TOKEN ) ;
153
- newChildModules . forEach ( module => applyModuleConfig ( uiRouter , injector , module ) ) ;
157
+ let newStateObjects : StateObject [ ] = newChildModules
158
+ . map ( module => applyModuleConfig ( uiRouter , injector , module ) )
159
+ . reduce ( unnestR , [ ] )
160
+ . reduce ( uniqR , [ ] ) ;
154
161
155
162
let replacementState = registry . get ( replacementName ) ;
156
163
if ( ! replacementState || replacementState === originalState ) {
@@ -164,16 +171,11 @@ export function applyNgModule(transition: Transition, ng2Module: NgModuleRef<any
164
171
// Supply the newly loaded states with the Injector from the lazy loaded NgModule.
165
172
// If a tree of states is lazy loaded, only add the injector to the root of the lazy loaded tree.
166
173
// The children will get the injector by resolve inheritance.
167
- let newStates = newChildModules . map ( module => module . states )
168
- . reduce ( unnestR , [ ] )
169
- . map ( state => state . $$state ( ) ) ;
170
-
171
- let newParentStates = newStates . filter ( state => ! inArray ( newStates , state . parent ) ) ;
174
+ let newParentStates = newStateObjects . filter ( state => ! inArray ( newStateObjects , state . parent ) ) ;
172
175
173
176
// Add the Injector to the top of the lazy loaded state tree as a resolve
174
177
newParentStates . forEach ( state => state . resolvables . push ( Resolvable . fromData ( NATIVE_INJECTOR_TOKEN , injector ) ) ) ;
175
178
176
-
177
179
return { } ;
178
180
}
179
181
0 commit comments