Skip to content

Commit d27d32b

Browse files
committed
use const whenever possible
1 parent d583a3f commit d27d32b

File tree

8 files changed

+68
-68
lines changed

8 files changed

+68
-68
lines changed

src/directives/view.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ import { activate } from '../pipeline'
33

44
export default function (Vue) {
55

6-
let _ = Vue.util
7-
let componentDef =
6+
const _ = Vue.util
7+
const componentDef =
88
// 0.12
99
Vue.directive('_component') ||
1010
// 1.0
1111
Vue.internalDirectives.component
1212
// <router-view> extends the internal component directive
13-
let viewDef = _.extend({}, componentDef)
13+
const viewDef = _.extend({}, componentDef)
1414

1515
// with some overrides
1616
_.extend(viewDef, {
1717

1818
_isRouterView: true,
1919

2020
bind () {
21-
let route = this.vm.$route
21+
const route = this.vm.$route
2222
/* istanbul ignore if */
2323
if (!route) {
2424
warn(
@@ -52,7 +52,7 @@ export default function (Vue) {
5252
parentView.childView = this
5353
} else {
5454
// this is the root view!
55-
let router = route.router
55+
const router = route.router
5656
router._rootView = this
5757
}
5858

src/history/hash.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ export default class HashHistory {
88
}
99

1010
start () {
11-
let self = this
11+
const self = this
1212
this.listener = function () {
13-
let path = location.hash
13+
const path = location.hash
1414
let raw = path.replace(/^#!?/, '')
1515
// always
1616
if (raw.charAt(0) !== '/') {
1717
raw = '/' + raw
1818
}
19-
let formattedPath = self.formatPath(raw)
19+
const formattedPath = self.formatPath(raw)
2020
if (formattedPath !== path) {
2121
location.replace(formattedPath)
2222
return
2323
}
2424
// determine query
2525
// note it's possible to have queries in both the actual URL
2626
// and the hash fragment itself.
27-
let query = location.search && path.indexOf('?') > -1
27+
const query = location.search && path.indexOf('?') > -1
2828
? '&' + location.search.slice(1)
2929
: location.search
3030
self.onChange(decodeURI(path.replace(/^#!?/, '') + query))
@@ -47,8 +47,8 @@ export default class HashHistory {
4747
}
4848

4949
formatPath (path, append) {
50-
let isAbsoloute = path.charAt(0) === '/'
51-
let prefix = '#' + (this.hashbang ? '!' : '')
50+
const isAbsoloute = path.charAt(0) === '/'
51+
const prefix = '#' + (this.hashbang ? '!' : '')
5252
return isAbsoloute
5353
? prefix + path
5454
: prefix + resolvePath(

src/history/html5.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default class HTML5History {
1717
}
1818
this.onChange = onChange
1919
// check base tag
20-
let baseEl = document.querySelector('base')
20+
const baseEl = document.querySelector('base')
2121
this.base = baseEl && baseEl.getAttribute('href')
2222
}
2323

@@ -38,7 +38,7 @@ export default class HTML5History {
3838
}
3939

4040
go (path, replace, append) {
41-
let url = this.formatPath(path, append)
41+
const url = this.formatPath(path, append)
4242
if (replace) {
4343
history.replaceState({}, '', url)
4444
} else {
@@ -52,8 +52,8 @@ export default class HTML5History {
5252
// then push new state
5353
history.pushState({}, '', url)
5454
}
55-
let hashMatch = path.match(hashRE)
56-
let hash = hashMatch && hashMatch[0]
55+
const hashMatch = path.match(hashRE)
56+
const hash = hashMatch && hashMatch[0]
5757
path = url
5858
// strip hash so it doesn't mess up params
5959
.replace(hashRE, '')

src/index.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ class Router {
8585
this._suppress = suppressTransitionError
8686

8787
// create history object
88-
let inBrowser = Vue.util.inBrowser
88+
const inBrowser = Vue.util.inBrowser
8989
this.mode = (!inBrowser || this._abstract)
9090
? 'abstract'
9191
: this._history
9292
? 'html5'
9393
: 'hash'
9494

95-
let History = historyBackends[this.mode]
96-
let self = this
95+
const History = historyBackends[this.mode]
96+
const self = this
9797
this.history = new History({
9898
root: root,
9999
hashbang: this._hashbang,
@@ -364,7 +364,7 @@ class Router {
364364
this._guardRecognizer.add([{
365365
path: path,
366366
handler: (match, query) => {
367-
let realPath = mapParams(
367+
const realPath = mapParams(
368368
mappedPath,
369369
match.params,
370370
query
@@ -409,8 +409,8 @@ class Router {
409409
return
410410
}
411411

412-
let currentRoute = this._currentRoute
413-
let currentTransition = this._currentTransition
412+
const currentRoute = this._currentRoute
413+
const currentTransition = this._currentTransition
414414

415415
if (currentTransition) {
416416
if (currentTransition.to.path === path) {
@@ -430,8 +430,8 @@ class Router {
430430
}
431431

432432
// construct new route and transition context
433-
let route = new Route(path, this)
434-
let transition = new Transition(this, route, currentRoute)
433+
const route = new Route(path, this)
434+
const transition = new Transition(this, route, currentRoute)
435435

436436
// current transition is updated right now.
437437
// however, current route will only be updated after the transition has
@@ -454,8 +454,8 @@ class Router {
454454
}
455455

456456
// check global before hook
457-
let beforeHooks = this._beforeEachHooks
458-
let startTransition = () => {
457+
const beforeHooks = this._beforeEachHooks
458+
const startTransition = () => {
459459
transition.start(() => {
460460
this._postTransition(route, state, anchor)
461461
})
@@ -494,7 +494,7 @@ class Router {
494494

495495
_onTransitionValidated (transition) {
496496
// set current route
497-
let route = this._currentRoute = transition.to
497+
const route = this._currentRoute = transition.to
498498
// update route context for all children
499499
if (this.app.$route !== route) {
500500
this.app.$route = route
@@ -524,14 +524,14 @@ class Router {
524524
// handle scroll positions
525525
// saved scroll positions take priority
526526
// then we check if the path has an anchor
527-
let pos = state && state.pos
527+
const pos = state && state.pos
528528
if (pos && this._saveScrollPosition) {
529529
Vue.nextTick(() => {
530530
window.scrollTo(pos.x, pos.y)
531531
})
532532
} else if (anchor) {
533533
Vue.nextTick(() => {
534-
let el = document.getElementById(anchor.slice(1))
534+
const el = document.getElementById(anchor.slice(1))
535535
if (el) {
536536
window.scrollTo(window.scrollX, el.offsetTop)
537537
}

src/pipeline.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
*/
1414

1515
export function canReuse (view, handler, transition) {
16-
let component = view.childVM
16+
const component = view.childVM
1717
if (!component || !handler) {
1818
return false
1919
}
@@ -22,7 +22,7 @@ export function canReuse (view, handler, transition) {
2222
if (view.Component !== handler.component) {
2323
return false
2424
}
25-
let canReuseFn = getRouteConfig(component, 'canReuse')
25+
const canReuseFn = getRouteConfig(component, 'canReuse')
2626
return typeof canReuseFn === 'boolean'
2727
? canReuseFn
2828
: canReuseFn
@@ -41,8 +41,8 @@ export function canReuse (view, handler, transition) {
4141
*/
4242

4343
export function canDeactivate (view, transition, next) {
44-
let fromComponent = view.childVM
45-
let hook = getRouteConfig(fromComponent, 'canDeactivate')
44+
const fromComponent = view.childVM
45+
const hook = getRouteConfig(fromComponent, 'canDeactivate')
4646
if (!hook) {
4747
next()
4848
} else {
@@ -67,7 +67,7 @@ export function canActivate (handler, transition, next) {
6767
return
6868
}
6969
// determine if this component can be activated
70-
let hook = getRouteConfig(Component, 'canActivate')
70+
const hook = getRouteConfig(Component, 'canActivate')
7171
if (!hook) {
7272
next()
7373
} else {
@@ -87,8 +87,8 @@ export function canActivate (handler, transition, next) {
8787
*/
8888

8989
export function deactivate (view, transition, next) {
90-
let component = view.childVM
91-
let hook = getRouteConfig(component, 'deactivate')
90+
const component = view.childVM
91+
const hook = getRouteConfig(component, 'deactivate')
9292
if (!hook) {
9393
next()
9494
} else {
@@ -106,7 +106,7 @@ export function deactivate (view, transition, next) {
106106
*/
107107

108108
export function activate (view, transition, depth, cb, reuse) {
109-
let handler = transition.activateQueue[depth]
109+
const handler = transition.activateQueue[depth]
110110
if (!handler) {
111111
saveChildView(view)
112112
if (view._bound) {
@@ -116,16 +116,16 @@ export function activate (view, transition, depth, cb, reuse) {
116116
return
117117
}
118118

119-
let Component = view.Component = handler.component
120-
let activateHook = getRouteConfig(Component, 'activate')
121-
let dataHook = getRouteConfig(Component, 'data')
122-
let waitForData = getRouteConfig(Component, 'waitForData')
119+
const Component = view.Component = handler.component
120+
const activateHook = getRouteConfig(Component, 'activate')
121+
const dataHook = getRouteConfig(Component, 'data')
122+
const waitForData = getRouteConfig(Component, 'waitForData')
123123

124124
view.depth = depth
125125
view.activated = false
126126

127127
let component
128-
let loading = !!(dataHook && !waitForData)
128+
const loading = !!(dataHook && !waitForData)
129129

130130
// "reuse" is a flag passed down when the parent view is
131131
// either reused via keep-alive or as a child of a kept-alive view.
@@ -162,7 +162,7 @@ export function activate (view, transition, depth, cb, reuse) {
162162
// and also properly update current view's child view.
163163
if (view.keepAlive) {
164164
component.$loadingRouteData = loading
165-
let cachedChildView = component._keepAliveRouterView
165+
const cachedChildView = component._keepAliveRouterView
166166
if (cachedChildView) {
167167
view.childView = cachedChildView
168168
component._keepAliveRouterView = null
@@ -172,17 +172,17 @@ export function activate (view, transition, depth, cb, reuse) {
172172

173173
// cleanup the component in case the transition is aborted
174174
// before the component is ever inserted.
175-
let cleanup = () => {
175+
const cleanup = () => {
176176
component.$destroy()
177177
}
178178

179179
// actually insert the component and trigger transition
180-
let insert = () => {
180+
const insert = () => {
181181
if (reuse) {
182182
cb && cb()
183183
return
184184
}
185-
let router = transition.router
185+
const router = transition.router
186186
if (router._rendered || router._transitionOnLoad) {
187187
view.transition(component)
188188
} else {
@@ -201,7 +201,7 @@ export function activate (view, transition, depth, cb, reuse) {
201201
}
202202

203203
// called after activation hook is resolved
204-
let afterActivate = () => {
204+
const afterActivate = () => {
205205
view.activated = true
206206
// activate the child view
207207
if (view.childView) {
@@ -234,8 +234,8 @@ export function activate (view, transition, depth, cb, reuse) {
234234
*/
235235

236236
export function reuse (view, transition) {
237-
let component = view.childVM
238-
let dataHook = getRouteConfig(component, 'data')
237+
const component = view.childVM
238+
const dataHook = getRouteConfig(component, 'data')
239239
if (dataHook) {
240240
loadData(component, transition, dataHook)
241241
}
@@ -266,10 +266,10 @@ function loadData (component, transition, hook, cb, cleanup) {
266266
}, Object.create(null))
267267
}
268268
// handle promise sugar syntax
269-
let promises = []
269+
const promises = []
270270
if (isPlainObject(data)) {
271271
Object.keys(data).forEach(key => {
272-
let val = data[key]
272+
const val = data[key]
273273
if (isPromise(val)) {
274274
promises.push(val.then(resolvedVal => {
275275
component.$set(key, resolvedVal)
@@ -312,7 +312,7 @@ function saveChildView (view) {
312312

313313
/**
314314
* Check plain object.
315-
*
315+
*
316316
* @param {*} val
317317
*/
318318

src/route.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const internalKeysRE = /^(component|subRoutes)$/
1010
export default class Route {
1111

1212
constructor (path, router) {
13-
let matched = router._recognizer.recognize(path)
13+
const matched = router._recognizer.recognize(path)
1414
if (matched) {
1515
// copy all custom fields from route configs
1616
[].forEach.call(matched, match => {

0 commit comments

Comments
 (0)