Skip to content

Commit a6b4df4

Browse files
chore(tslint): prefer-const
1 parent 9b84be1 commit a6b4df4

File tree

11 files changed

+56
-56
lines changed

11 files changed

+56
-56
lines changed

src/directives/uiSref.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,20 +146,20 @@ export class UISref implements OnChanges {
146146
}
147147

148148
private update() {
149-
let $state = this._router.stateService;
149+
const $state = this._router.stateService;
150150
if (this._emit) {
151-
let newTarget = $state.target(this.state, this.params, this.getOptions());
151+
const newTarget = $state.target(this.state, this.params, this.getOptions());
152152
this.targetState$.next(newTarget);
153153
}
154154

155155
if (this._anchorUISref) {
156-
let href = $state.href(this.state, this.params, this.getOptions());
156+
const href = $state.href(this.state, this.params, this.getOptions());
157157
this._anchorUISref.update(href);
158158
}
159159
}
160160

161161
getOptions() {
162-
let defaultOpts: TransitionOptions = {
162+
const defaultOpts: TransitionOptions = {
163163
relative: this._parent && this._parent.context && this._parent.context.name,
164164
inherit: true ,
165165
source: "sref"

src/directives/uiSrefStatus.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,17 @@ const inactiveStatus: SrefStatus = {
5555
*/
5656
const pathMatches = (target: TargetState): Predicate<PathNode[]> => {
5757
if (!target.exists()) return () => false;
58-
let state: StateObject = target.$state();
59-
let targetParamVals = target.params();
60-
let targetPath: PathNode[] = PathUtils.buildPath(target);
61-
let paramSchema: Param[] = targetPath.map(node => node.paramSchema)
58+
const state: StateObject = target.$state();
59+
const targetParamVals = target.params();
60+
const targetPath: PathNode[] = PathUtils.buildPath(target);
61+
const paramSchema: Param[] = targetPath.map(node => node.paramSchema)
6262
.reduce(unnestR, [])
6363
.filter((param: Param) => targetParamVals.hasOwnProperty(param.id));
6464

6565
return (path: PathNode[]) => {
66-
let tailNode = tail(path);
66+
const tailNode = tail(path);
6767
if (!tailNode || tailNode.state !== state) return false;
68-
let paramValues = PathUtils.paramValues(path);
68+
const paramValues = PathUtils.paramValues(path);
6969
return Param.equals(paramSchema, paramValues, targetParamVals);
7070
};
7171
};
@@ -93,9 +93,9 @@ function getSrefStatus(event: TransEvt, srefTarget: TargetState): SrefStatus {
9393
const pathMatchesTarget = pathMatches(srefTarget);
9494
const tc = event.trans.treeChanges();
9595

96-
let isStartEvent = event.evt === 'start';
97-
let isSuccessEvent = event.evt === 'success';
98-
let activePath: PathNode[] = isSuccessEvent ? tc.to : tc.from;
96+
const isStartEvent = event.evt === 'start';
97+
const isSuccessEvent = event.evt === 'success';
98+
const activePath: PathNode[] = isSuccessEvent ? tc.to : tc.from;
9999

100100
const isActive = () =>
101101
spreadToSubPaths([], activePath)
@@ -208,12 +208,12 @@ export class UISrefStatus {
208208
ngAfterContentInit() {
209209
// Map each transition start event to a stream of:
210210
// start -> (success|error)
211-
let transEvents$: Observable<TransEvt> = switchMap.call(this._globals.start$, (trans: Transition) => {
211+
const transEvents$: Observable<TransEvt> = switchMap.call(this._globals.start$, (trans: Transition) => {
212212
const event = (evt: string) => ({evt, trans} as TransEvt);
213213

214-
let transStart$ = of(event("start"));
215-
let transResult = trans.promise.then(() => event("success"), () => event("error"));
216-
let transFinish$ = fromPromise(transResult);
214+
const transStart$ = of(event("start"));
215+
const transResult = trans.promise.then(() => event("success"), () => event("error"));
216+
const transFinish$ = fromPromise(transResult);
217217

218218
return concat.call(transStart$, transFinish$);
219219
});
@@ -224,15 +224,15 @@ export class UISrefStatus {
224224
this._srefs$ = new BehaviorSubject(this._srefs.toArray());
225225
this._srefChangesSub = this._srefs.changes.subscribe(srefs => this._srefs$.next(srefs));
226226

227-
let targetStates$: Observable<TargetState[]> =
227+
const targetStates$: Observable<TargetState[]> =
228228
switchMap.call(this._srefs$, (srefs: UISref[]) =>
229229
combineLatest<TargetState[]>(srefs.map(sref => sref.targetState$)));
230230

231231
// Calculate the status of each UISref based on the transition event.
232232
// Reduce the statuses (if multiple) by or-ing each flag.
233233
this._subscription = switchMap.call(transEvents$, (evt: TransEvt) => {
234234
return map.call(targetStates$, (targets: TargetState[]) => {
235-
let statuses: SrefStatus[] = targets.map(target => getSrefStatus(evt, target));
235+
const statuses: SrefStatus[] = targets.map(target => getSrefStatus(evt, target));
236236
return statuses.reduce(mergeSrefStatus);
237237
});
238238
}).subscribe(this._setStatus.bind(this));

src/directives/uiView.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,15 @@ export class UIView {
205205
private _applyUpdatedConfig(config: Ng2ViewConfig) {
206206
this._uiViewData.config = config;
207207
// Create the Injector for the routed component
208-
let context = new ResolveContext(config.path);
209-
let componentInjector = this._getComponentInjector(context);
208+
const context = new ResolveContext(config.path);
209+
const componentInjector = this._getComponentInjector(context);
210210

211211
// Get the component class from the view declaration. TODO: allow promises?
212-
let componentClass = config.viewDecl.component;
212+
const componentClass = config.viewDecl.component;
213213

214214
// Create the component
215-
let compFactoryResolver = componentInjector.get(ComponentFactoryResolver);
216-
let compFactory = compFactoryResolver.resolveComponentFactory(componentClass);
215+
const compFactoryResolver = componentInjector.get(ComponentFactoryResolver);
216+
const compFactory = compFactoryResolver.resolveComponentFactory(componentClass);
217217
this._componentRef = this._componentTarget.createComponent(compFactory, undefined, componentInjector);
218218

219219
// Wire resolves to @Input()s
@@ -232,15 +232,15 @@ export class UIView {
232232
*/
233233
private _getComponentInjector(context: ResolveContext): Injector {
234234
// Map resolves to "useValue: providers"
235-
let resolvables = context.getTokens().map(token => context.getResolvable(token)).filter(r => r.resolved);
236-
let newProviders = resolvables.map(r => ({ provide: r.token, useValue: r.data }));
235+
const resolvables = context.getTokens().map(token => context.getResolvable(token)).filter(r => r.resolved);
236+
const newProviders = resolvables.map(r => ({ provide: r.token, useValue: r.data }));
237237

238-
let parentInject = { context: this._uiViewData.config.viewDecl.$context, fqn: this._uiViewData.fqn };
238+
const parentInject = { context: this._uiViewData.config.viewDecl.$context, fqn: this._uiViewData.fqn };
239239
newProviders.push({ provide: UIView.PARENT_INJECT, useValue: parentInject });
240240

241-
let parentComponentInjector = this.viewContainerRef.injector;
242-
let moduleInjector = context.getResolvable(NATIVE_INJECTOR_TOKEN).data;
243-
let mergedParentInjector = new MergeInjector(moduleInjector, parentComponentInjector);
241+
const parentComponentInjector = this.viewContainerRef.injector;
242+
const moduleInjector = context.getResolvable(NATIVE_INJECTOR_TOKEN).data;
243+
const mergedParentInjector = new MergeInjector(moduleInjector, parentComponentInjector);
244244

245245
return ReflectiveInjector.resolveAndCreate(newProviders, mergedParentInjector);
246246
}

src/lazyLoad/lazyLoadNgModule.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,34 +132,34 @@ export function loadModuleFactory(moduleToLoad: NgModuleToLoad, ng2Injector: Inj
132132
* @internalapi
133133
*/
134134
export function applyNgModule(transition: Transition, ng2Module: NgModuleRef<any>, parentInjector: Injector, lazyLoadState: StateDeclaration): LazyLoadResult {
135-
let injector = ng2Module.injector;
136-
let uiRouter: UIRouter = injector.get(UIRouter);
137-
let registry = uiRouter.stateRegistry;
135+
const injector = ng2Module.injector;
136+
const uiRouter: UIRouter = injector.get(UIRouter);
137+
const registry = uiRouter.stateRegistry;
138138

139-
let originalName = lazyLoadState.name;
140-
let originalState = registry.get(originalName);
139+
const originalName = lazyLoadState.name;
140+
const originalState = registry.get(originalName);
141141
// Check if it's a future state (ends with .**)
142-
let isFuture = /^(.*)\.\*\*$/.exec(originalName);
142+
const isFuture = /^(.*)\.\*\*$/.exec(originalName);
143143
// Final name (without the .**)
144-
let replacementName = isFuture && isFuture[1];
144+
const replacementName = isFuture && isFuture[1];
145145

146-
let newRootModules = multiProviderParentChildDelta(parentInjector, injector, UIROUTER_ROOT_MODULE)
146+
const newRootModules = multiProviderParentChildDelta(parentInjector, injector, UIROUTER_ROOT_MODULE)
147147
.reduce(uniqR, []) as RootModule[];
148-
let newChildModules= multiProviderParentChildDelta(parentInjector, injector, UIROUTER_MODULE_TOKEN)
148+
const newChildModules= multiProviderParentChildDelta(parentInjector, injector, UIROUTER_MODULE_TOKEN)
149149
.reduce(uniqR, []) as StatesModule[];
150150

151151
if (newRootModules.length) {
152152
console.log(newRootModules); // tslint:disable-line:no-console
153153
throw new Error('Lazy loaded modules should not contain a UIRouterModule.forRoot() module');
154154
}
155155

156-
let newStateObjects: StateObject[] = newChildModules
156+
const newStateObjects: StateObject[] = newChildModules
157157
.map(module => applyModuleConfig(uiRouter, injector, module))
158158
.reduce(unnestR, [])
159159
.reduce(uniqR, []);
160160

161161
if (isFuture) {
162-
let replacementState = registry.get(replacementName);
162+
const replacementState = registry.get(replacementName);
163163
if (!replacementState || replacementState === originalState) {
164164
throw new Error(`The Future State named '${originalName}' lazy loaded an NgModule. ` +
165165
`The lazy loaded NgModule must have a state named '${replacementName}' ` +
@@ -172,7 +172,7 @@ export function applyNgModule(transition: Transition, ng2Module: NgModuleRef<any
172172
// Supply the newly loaded states with the Injector from the lazy loaded NgModule.
173173
// If a tree of states is lazy loaded, only add the injector to the root of the lazy loaded tree.
174174
// The children will get the injector by resolve inheritance.
175-
let newParentStates = newStateObjects.filter(state => !inArray(newStateObjects, state.parent));
175+
const newParentStates = newStateObjects.filter(state => !inArray(newStateObjects, state.parent));
176176

177177
// Add the Injector to the top of the lazy loaded state tree as a resolve
178178
newParentStates.forEach(state => state.resolvables.push(Resolvable.fromData(NATIVE_INJECTOR_TOKEN, injector)));
@@ -191,7 +191,7 @@ export function applyNgModule(transition: Transition, ng2Module: NgModuleRef<any
191191
* @internalapi
192192
*/
193193
export function multiProviderParentChildDelta(parent: Injector, child: Injector, token: any) {
194-
let childVals: RootModule[] = child.get(token, []);
195-
let parentVals: RootModule[] = parent.get(token, []);
194+
const childVals: RootModule[] = child.get(token, []);
195+
const parentVals: RootModule[] = parent.get(token, []);
196196
return childVals.filter(val => parentVals.indexOf(val) === -1);
197197
}

src/location/locationService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ export class Ng2LocationServices extends BaseLocationServices {
2121
}
2222

2323
_set(state: any, title: string, url: string, replace: boolean): any {
24-
let { path, search, hash } = parseUrl(url);
25-
let urlWithHash = path + (hash ? "#" + hash : "");
24+
const { path, search, hash } = parseUrl(url);
25+
const urlWithHash = path + (hash ? "#" + hash : "");
2626

2727
if (replace) {
2828
this._locationStrategy.replaceState(state, title, urlWithHash, search);

src/mergeInjector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class MergeInjector implements Injector {
2828
*/
2929
get(token: any, notFoundValue?: any): any {
3030
for (let i = 0; i < this.injectors.length; i++) {
31-
let val = this.injectors[i].get(token, MergeInjector.NOT_FOUND);
31+
const val = this.injectors[i].get(token, MergeInjector.NOT_FOUND);
3232
if (val !== MergeInjector.NOT_FOUND) return val;
3333
}
3434

src/providers.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export function uiRouterFactory(locationStrategy: LocationStrategy, rootModules:
116116

117117
// ----------------- Create router -----------------
118118
// Create a new ng2 UIRouter and configure it for ng2
119-
let router = new UIRouter();
119+
const router = new UIRouter();
120120

121121
// Add RxJS plugin
122122
router.plugin(UIRouterRx);
@@ -135,16 +135,16 @@ export function uiRouterFactory(locationStrategy: LocationStrategy, rootModules:
135135
router.locationConfig = new Ng2LocationConfig(router, locationStrategy);
136136

137137
// Apply ng2 ui-view handling code
138-
let viewConfigFactory = (path: PathNode[], config: Ng2ViewDeclaration) => new Ng2ViewConfig(path, config);
138+
const viewConfigFactory = (path: PathNode[], config: Ng2ViewDeclaration) => new Ng2ViewConfig(path, config);
139139
router.viewService._pluginapi._viewConfigFactory("ng2", viewConfigFactory);
140140

141141
// Apply statebuilder decorator for ng2 NgModule registration
142-
let registry = router.stateRegistry;
142+
const registry = router.stateRegistry;
143143
registry.decorator('views', ng2ViewsBuilder);
144144
registry.decorator('lazyLoad', ng2LazyLoadBuilder);
145145

146146
// Prep the tree of NgModule by placing the root NgModule's Injector on the root state.
147-
let ng2InjectorResolvable = Resolvable.fromData(NATIVE_INJECTOR_TOKEN, injector);
147+
const ng2InjectorResolvable = Resolvable.fromData(NATIVE_INJECTOR_TOKEN, injector);
148148
registry.root().resolvables.push(ng2InjectorResolvable);
149149

150150
// Auto-flush the parameter type queue

src/statebuilders/lazyLoad.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ import { loadNgModule } from "../lazyLoad/lazyLoadNgModule";
4848
*
4949
*/
5050
export function ng2LazyLoadBuilder(state: StateObject, parent: BuilderFunction) {
51-
let loadNgModuleFn = state['loadChildren'];
51+
const loadNgModuleFn = state['loadChildren'];
5252
return loadNgModuleFn ? loadNgModule(loadNgModuleFn) : state.lazyLoad;
5353
}

src/statebuilders/views.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {ViewService} from "@uirouter/core";
1717
* applies the state-level configuration to a view named `$default`.
1818
*/
1919
export function ng2ViewsBuilder(state: StateObject) {
20-
let views: { [key: string]: Ng2ViewDeclaration } = {},
20+
const views: { [key: string]: Ng2ViewDeclaration } = {},
2121
viewsObject = state.views || {"$default": pick(state, ["component", "bindings"])};
2222

2323
forEach(viewsObject, function (config: Ng2ViewDeclaration, name: string) {
@@ -29,7 +29,7 @@ export function ng2ViewsBuilder(state: StateObject) {
2929
config.$context = state;
3030
config.$name = name;
3131

32-
let normalized = ViewService.normalizeUIViewTarget(config.$context, config.$name);
32+
const normalized = ViewService.normalizeUIViewTarget(config.$context, config.$name);
3333
config.$uiViewName = normalized.uiViewName;
3434
config.$uiViewContextAnchor = normalized.uiViewContextAnchor;
3535

src/uiRouterConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export function applyModuleConfig(uiRouter: UIRouter, injector: Injector, module
99
module.config(uiRouter, injector, module);
1010
}
1111

12-
let states = module.states || [];
12+
const states = module.states || [];
1313
return states.map(state => uiRouter.stateRegistry.register(state));
1414
}
1515

0 commit comments

Comments
 (0)