Skip to content

Commit 8088ef9

Browse files
committed
Aot support
1 parent 9647049 commit 8088ef9

File tree

3 files changed

+42
-31
lines changed

3 files changed

+42
-31
lines changed

src/ng2/directives/uiSrefStatus.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function spreadToSubPaths(basePath: PathNode[], appendPath: PathNode[]): PathNod
7575
/**
7676
* Given a TransEvt (Transition event: started, success, error)
7777
* and a UISref Target State, return a SrefStatus object
78-
* which represents the current status of that Sref:
78+
* which represents the current status of that Sref:
7979
* active, activeEq (exact match), entering, exiting
8080
*
8181
* @internalapi

src/ng2/providers.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* - [quick start repository](http://github.com/ui-router/quickstart-ng2)
77
*
88
* Getting started:
9-
*
9+
*
1010
* - Use npm. Add a dependency on latest `ui-router-ng2`
1111
* - Import UI-Router classes directly from `"ui-router-ng2"`
1212
*
@@ -111,9 +111,7 @@ import {NATIVE_INJECTOR_TOKEN} from "ui-router-core";
111111
* Creates a UIRouter instance and configures it for Angular 2, then invokes router bootstrap.
112112
* This function is used as an Angular 2 `useFactory` Provider.
113113
*/
114-
let uiRouterFactory = (
115-
location: UIRouterLocation,
116-
injector: Injector) => {
114+
export function uiRouterFactory(location: UIRouterLocation, injector: Injector) {
117115

118116
let rootModules: RootModule[] = injector.get(UIROUTER_ROOT_MODULE);
119117
let modules: StatesModule[] = injector.get(UIROUTER_MODULE_TOKEN);
@@ -167,20 +165,30 @@ let uiRouterFactory = (
167165
return router;
168166
};
169167

168+
export function parentUIViewInjectFactory(r: StateRegistry) { return { fqn: null, context: r.root() } as ParentUIViewInject; }
169+
170170
export const _UIROUTER_INSTANCE_PROVIDERS: Provider[] = [
171171
{ provide: UIRouter, useFactory: uiRouterFactory, deps: [UIRouterLocation, Injector] },
172172
{ provide: UIRouterLocation, useClass: UIRouterLocation },
173-
{ provide: UIView.PARENT_INJECT, useFactory: (r: StateRegistry) => { return { fqn: null, context: r.root() } as ParentUIViewInject }, deps: [StateRegistry]},
173+
{ provide: UIView.PARENT_INJECT, useFactory: parentUIViewInjectFactory, deps: [StateRegistry]},
174174
];
175175

176+
export function fnStateService(r: UIRouter) { return r.stateService; }
177+
export function fnTransitionService(r: UIRouter) { return r.transitionService; }
178+
export function fnUrlMatcherFactory(r: UIRouter) { return r.urlMatcherFactory; }
179+
export function fnUrlRouter(r: UIRouter) { return r.urlRouter; }
180+
export function fnViewService(r: UIRouter) { return r.viewService; }
181+
export function fnStateRegistry(r: UIRouter) { return r.stateRegistry; }
182+
export function fnGlobals(r: any) { return r.globals; }
183+
176184
export const _UIROUTER_SERVICE_PROVIDERS: Provider[] = [
177-
{ provide: StateService, useFactory: (r: UIRouter) => r.stateService , deps: [UIRouter]},
178-
{ provide: TransitionService, useFactory: (r: UIRouter) => r.transitionService, deps: [UIRouter]},
179-
{ provide: UrlMatcherFactory, useFactory: (r: UIRouter) => r.urlMatcherFactory, deps: [UIRouter]},
180-
{ provide: UrlRouter, useFactory: (r: UIRouter) => r.urlRouter , deps: [UIRouter]},
181-
{ provide: ViewService, useFactory: (r: UIRouter) => r.viewService , deps: [UIRouter]},
182-
{ provide: StateRegistry, useFactory: (r: UIRouter) => r.stateRegistry , deps: [UIRouter]},
183-
{ provide: Globals, useFactory: (r: UIRouter) => r.globals , deps: [UIRouter]},
185+
{ provide: StateService, useFactory: fnStateService, deps: [UIRouter]},
186+
{ provide: TransitionService, useFactory: fnTransitionService, deps: [UIRouter]},
187+
{ provide: UrlMatcherFactory, useFactory: fnUrlMatcherFactory, deps: [UIRouter]},
188+
{ provide: UrlRouter, useFactory: fnUrlRouter, deps: [UIRouter]},
189+
{ provide: ViewService, useFactory: fnViewService, deps: [UIRouter]},
190+
{ provide: StateRegistry, useFactory: fnStateRegistry, deps: [UIRouter]},
191+
{ provide: Globals, useFactory: fnGlobals, deps: [UIRouter]},
184192
];
185193

186194
/**
@@ -189,4 +197,3 @@ export const _UIROUTER_SERVICE_PROVIDERS: Provider[] = [
189197
* @deprecated use [[UIRouterModule.forRoot]]
190198
*/
191199
export const UIROUTER_PROVIDERS: Provider[] = _UIROUTER_INSTANCE_PROVIDERS.concat(_UIROUTER_SERVICE_PROVIDERS);
192-

src/ng2/uiRouterNgModule.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,24 @@ import {identity} from "ui-router-core";
99
import {LocationStrategy, HashLocationStrategy, PathLocationStrategy} from "@angular/common";
1010
import {_UIROUTER_INSTANCE_PROVIDERS, _UIROUTER_SERVICE_PROVIDERS} from "./providers";
1111

12+
export function makeRootProviders(module: StatesModule): Provider[] {
13+
return [
14+
{ provide: UIROUTER_ROOT_MODULE, useValue: module, multi: true},
15+
{ provide: UIROUTER_MODULE_TOKEN, useValue: module, multi: true },
16+
{ provide: ANALYZE_FOR_ENTRY_COMPONENTS, useValue: module.states || [], multi: true },
17+
];
18+
}
19+
20+
export function makeChildProviders(module: StatesModule): Provider[] {
21+
return [
22+
{ provide: UIROUTER_MODULE_TOKEN, useValue: module, multi: true },
23+
{ provide: ANALYZE_FOR_ENTRY_COMPONENTS, useValue: module.states || [], multi: true },
24+
];
25+
}
26+
27+
export function locationStrategy(useHash) {
28+
return { provide: LocationStrategy, useClass: useHash ? HashLocationStrategy : PathLocationStrategy };
29+
}
1230

1331
/**
1432
* Creates UI-Router Modules
@@ -75,14 +93,13 @@ export class UIRouterModule {
7593
* @returns an `NgModule` which provides the [[UIRouter]] singleton instance
7694
*/
7795
static forRoot(config: RootModule = {}): ModuleWithProviders {
78-
let locationStrategy = config.useHash ? HashLocationStrategy : PathLocationStrategy;
7996
return {
8097
ngModule: UIRouterModule,
8198
providers: [
8299
_UIROUTER_INSTANCE_PROVIDERS,
83100
_UIROUTER_SERVICE_PROVIDERS,
84-
{ provide: LocationStrategy, useClass: locationStrategy },
85-
...makeProviders(config, true),
101+
locationStrategy(config.useHash),
102+
...makeRootProviders(config),
86103
]
87104
}
88105
}
@@ -114,25 +131,12 @@ export class UIRouterModule {
114131
static forChild(module: StatesModule = {}): ModuleWithProviders {
115132
return {
116133
ngModule: UIRouterModule,
117-
providers: makeProviders(module, false),
134+
providers: makeChildProviders(module),
118135
}
119136
}
120137

121138
}
122139

123-
/** @hidden */
124-
function makeProviders(module: StatesModule, forRoot: boolean): Provider[] {
125-
let providers: Provider[] = [module.configClass]
126-
.filter(identity)
127-
.map(configClass => ({ provide: configClass, useClass: configClass }));
128-
129-
if (forRoot) providers.push({ provide: UIROUTER_ROOT_MODULE, useValue: module, multi: true});
130-
providers.push({ provide: UIROUTER_MODULE_TOKEN, useValue: module, multi: true });
131-
providers.push({ provide: ANALYZE_FOR_ENTRY_COMPONENTS, useValue: module.states || [], multi: true });
132-
133-
return providers;
134-
}
135-
136140
/**
137141
* UI-Router declarative configuration which can be provided to [[UIRouterModule.forRoot]]
138142
*/

0 commit comments

Comments
 (0)