Skip to content

Commit 4a0dcaf

Browse files
refactor(static): Clean up imports and switch let to const
1 parent 27fa6dc commit 4a0dcaf

File tree

1 file changed

+29
-30
lines changed

1 file changed

+29
-30
lines changed

src/angular-hybrid.ts

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
import * as angular from 'angular';
22

3-
import { $InjectorLike, Ng1ViewConfig, StateObject, StateProvider } from '@uirouter/angularjs';
3+
44
import { Component, ElementRef, Inject, Injector, Input, NgModule } from '@angular/core';
55
import { downgradeComponent, UpgradeModule } from '@angular/upgrade/static';
6-
76
import {} from '@angular/upgrade';
87

8+
import { StateObject, forEach, PathNode, Resolvable, StateRegistry, UIRouter, ViewConfig, ViewService } from '@uirouter/core';
99
import {
10-
_UIROUTER_SERVICE_PROVIDERS, applyModuleConfig, forEach, NATIVE_INJECTOR_TOKEN, ng2LazyLoadBuilder, Ng2ViewConfig,
11-
Ng2ViewDeclaration, ParentUIViewInject, PathNode, Resolvable, StateRegistry, StatesModule, UIRouter,
12-
UIROUTER_MODULE_TOKEN, UIROUTER_ROOT_MODULE, UIRouterModule, UIView, ViewConfig, ViewService
10+
_UIROUTER_SERVICE_PROVIDERS, applyModuleConfig, NATIVE_INJECTOR_TOKEN, ng2LazyLoadBuilder, Ng2ViewConfig, UIView,
11+
Ng2ViewDeclaration, ParentUIViewInject, StatesModule, UIROUTER_MODULE_TOKEN, UIROUTER_ROOT_MODULE, UIRouterModule
1312
} from '@uirouter/angular';
14-
13+
import { $InjectorLike, Ng1ViewConfig, StateProvider } from '@uirouter/angularjs';
1514
import { UIRouterRx } from '@uirouter/rx';
1615

1716
/**
1817
* Create a ng1 module for the ng1 half of the hybrid application to depend on.
1918
*
2019
* Example:
21-
* let myApp = angular.module('myApp', ['ui.router.upgrade']);
20+
* const myApp = angular.module('myApp', ['ui.router.upgrade']);
2221
*/
23-
export let upgradeModule = angular.module('ui.router.upgrade', ['ui.router']);
24-
export let ng1InitModule = angular.module('ui.router.init');
22+
export const upgradeModule = angular.module('ui.router.upgrade', ['ui.router']);
23+
export const ng1InitModule = angular.module('ui.router.init');
2524

2625
/**
2726
* UIViewNgUpgrade is a component bridge from ng1 ui-view to ng2 ui-view
@@ -111,21 +110,21 @@ export class UIViewNgUpgrade {
111110

112111
// The ng2 ui-view component is inside this ui-view-ng-upgrade directive, which is inside the ng1 "host" ui-view.
113112
// Both ui-views share the same "view context" information (the view's fqn and created-by-state context information)
114-
let ng1elem = angular.element(ref.nativeElement).parent().parent();
113+
const ng1elem = angular.element(ref.nativeElement).parent().parent();
115114

116115
// Expose getters on PARENT_INJECT for context (creation state) and fqn (view address)
117116
// These will be used by further nested UIView
118117
Object.defineProperty(parent, "context", {
119118
get: function() {
120-
let data = ng1elem['inheritedData']('$uiView');
119+
const data = ng1elem['inheritedData']('$uiView');
121120
return (data && data.$cfg) ? data.$cfg.viewDecl.$context : registry.root();
122121
},
123122
enumerable: true
124123
});
125124

126125
Object.defineProperty(parent, "fqn", {
127126
get: function() {
128-
let data = ng1elem['inheritedData']('$uiView');
127+
const data = ng1elem['inheritedData']('$uiView');
129128
return (data && data.$uiView) ? data.$uiView.fqn : null;
130129
},
131130
enumerable: true
@@ -139,7 +138,7 @@ export class UIViewNgUpgrade {
139138

140139
// Register the ng1 DI '$uiRouter' object as an ng2 Provider.
141140
function uiRouterUpgradeFactory(router: UIRouter, injector: Injector) {
142-
let modules: StatesModule[] = injector.get(UIROUTER_MODULE_TOKEN, []);
141+
const modules: StatesModule[] = injector.get(UIROUTER_MODULE_TOKEN, []);
143142
modules.forEach(module => applyModuleConfig(router, injector, module));
144143
return router;
145144
}
@@ -182,20 +181,20 @@ upgradeModule.directive("uiViewNgUpgrade", <any> downgradeComponent({
182181
}));
183182

184183
upgradeModule.run(['$injector', (ng1Injector: $InjectorLike) => {
185-
let $uiRouter: UIRouter = ng1Injector.get('$uiRouter');
184+
const $uiRouter: UIRouter = ng1Injector.get('$uiRouter');
186185
new UIRouterRx($uiRouter);
187186

188187
// Expose a merged ng1/ng2 injector as a Resolvable (on the root state).
189188
// This mimics how ui-router-ng2 exposes the root ng2 Injector, but
190189
// it retrieves from ng1 injector first, then ng2 injector if the token isn't found.
191190
const mergedInjector = {
192191
get: function(token: any, ng2NotFoundValue?: any) {
193-
let ng2Injector = ng1Injector.get('$$angularInjector');
192+
const ng2Injector = ng1Injector.get('$$angularInjector');
194193
return (ng1Injector.has(token) && ng1Injector.get(token)) || ng2Injector.get(token, ng2NotFoundValue)
195194
}
196195
};
197196

198-
let ng2InjectorResolvable = Resolvable.fromData(NATIVE_INJECTOR_TOKEN, mergedInjector);
197+
const ng2InjectorResolvable = Resolvable.fromData(NATIVE_INJECTOR_TOKEN, mergedInjector);
199198
$uiRouter.stateRegistry.root().resolvables.push(ng2InjectorResolvable);
200199
}]);
201200

@@ -223,7 +222,7 @@ function applyHybridAdapter(ng2Injector: Injector) {
223222
}));
224223

225224
upgradeModule.run(['$injector', (ng1Injector: $InjectorLike) => {
226-
let $uiRouter: UIRouter = ng1Injector.get('$uiRouter');
225+
const $uiRouter: UIRouter = ng1Injector.get('$uiRouter');
227226

228227
// Expose a merged ng1/ng2 injector as a Resolvable (on the root state).
229228
// This mimics how @uirouter/angular exposes the root ng2 Injector, but
@@ -234,7 +233,7 @@ function applyHybridAdapter(ng2Injector: Injector) {
234233
}
235234
};
236235

237-
let ng2InjectorResolvable = Resolvable.fromData(NATIVE_INJECTOR_TOKEN, mergedInjector);
236+
const ng2InjectorResolvable = Resolvable.fromData(NATIVE_INJECTOR_TOKEN, mergedInjector);
238237
$uiRouter.stateRegistry.root().resolvables.push(ng2InjectorResolvable);
239238
}]);
240239

@@ -243,7 +242,7 @@ function applyHybridAdapter(ng2Injector: Injector) {
243242
}]);
244243

245244
upgradeModule.config(['$uiRouterProvider', ($uiRouterProvider: UIRouter) => {
246-
let registry = $uiRouterProvider.stateRegistry;
245+
const registry = $uiRouterProvider.stateRegistry;
247246

248247
/** Applies the `UIRouterRx` plugin for observable states/params */
249248
$uiRouterProvider.plugin(UIRouterRx);
@@ -265,7 +264,7 @@ function applyHybridAdapter(ng2Injector: Injector) {
265264
* which that provides a ng1 -> ng2 boundary in the component tree.
266265
*/
267266
registry.decorator('views', function(state: StateObject, parentFn: Function) {
268-
let views = parentFn(state);
267+
const views = parentFn(state);
269268

270269
forEach(views, (viewDecl: any, viewName: string) => {
271270
if (viewDecl.$type === 'ng1-to-ng2' || isNg2ComponentClass(viewDecl.component)) {
@@ -290,8 +289,8 @@ function applyHybridAdapter(ng2Injector: Injector) {
290289
// Register a ViewConfig factory for views of type `ng1-to-ng2`.
291290
// Returns both an ng1 config and an ng2 config allowing either ng1 or ng2 ui-view components to be targeted.
292291
$view._pluginapi._viewConfigFactory('ng1-to-ng2', (path: PathNode[], config: Ng2ViewDeclaration) => {
293-
let ng1ViewConfig: ViewConfig = <any> new Ng1ViewConfig(<any> path, <any> Object.assign({}, config, { $type: 'ng1'}), $templateFactory);
294-
let ng2ViewConfig: ViewConfig = <any> new Ng2ViewConfig(<any> path, <any> Object.assign({}, config, { $type: 'ng2'}));
292+
const ng1ViewConfig: ViewConfig = <any> new Ng1ViewConfig(<any> path, <any> Object.assign({}, config, { $type: 'ng1'}), $templateFactory);
293+
const ng2ViewConfig: ViewConfig = <any> new Ng2ViewConfig(<any> path, <any> Object.assign({}, config, { $type: 'ng2'}));
295294

296295
return [ ng2ViewConfig, ng1ViewConfig ];
297296
});
@@ -308,8 +307,8 @@ function applyHybridAdapter(ng2Injector: Injector) {
308307
* which that provides a ng1 -> ng2 boundary in the component tree.
309308
*/
310309
upgradeModule.config(['$stateProvider', ($stateProvider: StateProvider) => {
311-
$stateProvider.decorator('views', function(state: State, parentFn: Function) {
312-
let views = parentFn(state);
310+
$stateProvider.decorator('views', function(state: StateObject, parentFn: Function) {
311+
const views = parentFn(state);
313312

314313
forEach(views, (viewDecl: any, viewName: string) => {
315314
if (viewDecl.$type === 'ng1-to-ng2' || isNg2ComponentClass(viewDecl.component)) {
@@ -327,19 +326,19 @@ upgradeModule.config(['$stateProvider', ($stateProvider: StateProvider) => {
327326

328327
// UI-Router ViewConfig factories take a view declaration object from a state.views: { foo: <ViewDeclaration> }
329328
// and return a runtime config object (a ViewConfig)
330-
upgradeModule.run(['$view', ($view: ViewService) => {
329+
upgradeModule.run(['$view', '$templateFactory', ($view: ViewService, $templateFactory: any) => {
331330
// Register a ViewConfig factory for views of type `ng2`
332-
$view.viewConfigFactory('ng2', (path: PathNode[], config: Ng2ViewDeclaration) => new Ng2ViewConfig(path, config));
331+
$view._pluginapi._viewConfigFactory('ng2', (path: PathNode[], config: Ng2ViewDeclaration) => new Ng2ViewConfig(path, config));
333332

334333
// Register a ViewConfig factory for views of type `ng1-to-ng2`.
335334
// Returns both an ng1 config and an ng2 config allowing either ng1 or ng2 ui-view components to be targeted.
336-
$view.viewConfigFactory('ng1-to-ng2', (path: PathNode[], config: Ng2ViewDeclaration) => {
337-
var ng1ViewConfig: ViewConfig = <any> new Ng1ViewConfig(<any> path, <any> Object.assign({}, config, { $type: 'ng1'}));
338-
var ng2ViewConfig: ViewConfig = <any> new Ng2ViewConfig(<any> path, <any> Object.assign({}, config, { $type: 'ng2'}));
335+
$view._pluginapi._viewConfigFactory('ng1-to-ng2', (path: PathNode[], config: Ng2ViewDeclaration) => {
336+
const ng1ViewConfig: ViewConfig = <any> new Ng1ViewConfig(<any> path, <any> Object.assign({}, config, { $type: 'ng1'}), $templateFactory);
337+
const ng2ViewConfig: ViewConfig = <any> new Ng2ViewConfig(<any> path, <any> Object.assign({}, config, { $type: 'ng2'}));
339338

340339
return [ ng2ViewConfig, ng1ViewConfig ];
341340
});
342-
}])
341+
}]);
343342

344343
/** Predicate fn that returns true if an object is a NG2 Component Class */
345344
export function isNg2ComponentClass(def: any) {

0 commit comments

Comments
 (0)