Skip to content

Commit ece0e50

Browse files
committed
code cleanup
1 parent 8cdc765 commit ece0e50

File tree

6 files changed

+56
-55
lines changed

6 files changed

+56
-55
lines changed

src/history/abstract.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ function AbstractHistory (options) {
55
this.currentPath = '/'
66
}
77

8-
var p = AbstractHistory.prototype
9-
10-
p.start = function () {
8+
AbstractHistory.prototype.start = function () {
119
this.onChange('/')
1210
}
1311

14-
p.stop = function () {}
12+
AbstractHistory.prototype.stop = function () {
13+
// noop
14+
}
1515

16-
p.go = function (path) {
16+
AbstractHistory.prototype.go = function (path) {
1717
path = this.currentPath = this.formatPath(path)
1818
this.onChange(path)
1919
}
2020

21-
p.formatPath = function (path) {
21+
AbstractHistory.prototype.formatPath = function (path) {
2222
return path.charAt(0) === '/'
2323
? path
2424
: util.resolvePath(this.currentPath, path)

src/history/hash.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ function HashHistory (options) {
55
this.onChange = options.onChange
66
}
77

8-
var p = HashHistory.prototype
9-
10-
p.start = function () {
8+
HashHistory.prototype.start = function () {
119
var self = this
1210
this.listener = function () {
1311
var path = location.hash
@@ -25,11 +23,11 @@ p.start = function () {
2523
this.listener()
2624
}
2725

28-
p.stop = function () {
26+
HashHistory.prototype.stop = function () {
2927
window.removeEventListener('hashchange', this.listener)
3028
}
3129

32-
p.go = function (path, replace) {
30+
HashHistory.prototype.go = function (path, replace) {
3331
path = this.formatPath(path)
3432
if (replace) {
3533
location.replace(path)
@@ -38,7 +36,7 @@ p.go = function (path, replace) {
3836
}
3937
}
4038

41-
p.formatPath = function (path, expectAbsolute) {
39+
HashHistory.prototype.formatPath = function (path, expectAbsolute) {
4240
path = path.replace(/^#!?/, '')
4341
var isAbsoloute = path.charAt(0) === '/'
4442
if (expectAbsolute && !isAbsoloute) {

src/history/html5.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ function HTML5History (options) {
2020
this.base = baseEl && baseEl.getAttribute('href')
2121
}
2222

23-
var p = HTML5History.prototype
24-
25-
p.start = function () {
23+
HTML5History.prototype.start = function () {
2624
var self = this
2725
this.listener = function (e) {
2826
var url = decodeURI(location.pathname + location.search)
@@ -35,11 +33,11 @@ p.start = function () {
3533
this.listener()
3634
}
3735

38-
p.stop = function () {
36+
HTML5History.prototype.stop = function () {
3937
window.removeEventListener('popstate', this.listener)
4038
}
4139

42-
p.go = function (path, replace) {
40+
HTML5History.prototype.go = function (path, replace) {
4341
var root = this.root
4442
var url = this.formatPath(path, root)
4543
if (replace) {
@@ -65,7 +63,7 @@ p.go = function (path, replace) {
6563
this.onChange(path, null, hash)
6664
}
6765

68-
p.formatPath = function (path) {
66+
HTML5History.prototype.formatPath = function (path) {
6967
return path.charAt(0) === '/'
7068
// absolute path
7169
? this.root

src/router/api.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ var routerUtil = require('../util')
22

33
module.exports = function (Vue, Router) {
44

5-
var p = Router.prototype
6-
75
/**
86
* Register a map of top-level paths.
97
*/
108

11-
p.map = function (map) {
9+
Router.prototype.map = function (map) {
1210
for (var route in map) {
1311
this.on(route, map[route])
1412
}
@@ -26,7 +24,7 @@ module.exports = function (Vue, Router) {
2624
* - {Function} [after]
2725
*/
2826

29-
p.on = function (rootPath, handler) {
27+
Router.prototype.on = function (rootPath, handler) {
3028
if (rootPath === '*') {
3129
this._notFound(handler)
3230
} else {
@@ -40,7 +38,7 @@ module.exports = function (Vue, Router) {
4038
* @param {Object} map
4139
*/
4240

43-
p.redirect = function (map) {
41+
Router.prototype.redirect = function (map) {
4442
for (var path in map) {
4543
this._addRedirect(path, map[path])
4644
}
@@ -52,7 +50,7 @@ module.exports = function (Vue, Router) {
5250
* @param {Object} map
5351
*/
5452

55-
p.alias = function (map) {
53+
Router.prototype.alias = function (map) {
5654
for (var path in map) {
5755
this._addAlias(path, map[path])
5856
}
@@ -64,7 +62,7 @@ module.exports = function (Vue, Router) {
6462
* @param {Function} fn
6563
*/
6664

67-
p.beforeEach = function (fn) {
65+
Router.prototype.beforeEach = function (fn) {
6866
this._beforeEachHook = fn
6967
}
7068

@@ -77,7 +75,7 @@ module.exports = function (Vue, Router) {
7775
* @param {Boolean} [replace]
7876
*/
7977

80-
p.go = function (path, replace) {
78+
Router.prototype.go = function (path, replace) {
8179
this.history.go(path + '', replace)
8280
}
8381

@@ -87,7 +85,7 @@ module.exports = function (Vue, Router) {
8785
* @param {String} path
8886
*/
8987

90-
p.replace = function (path) {
88+
Router.prototype.replace = function (path) {
9189
this.go(path, true)
9290
}
9391

@@ -98,7 +96,7 @@ module.exports = function (Vue, Router) {
9896
* @param {String|Element} container
9997
*/
10098

101-
p.start = function (App, container) {
99+
Router.prototype.start = function (App, container) {
102100
/* istanbul ignore if */
103101
if (this._started) {
104102
routerUtil.warn('already started.')
@@ -125,7 +123,7 @@ module.exports = function (Vue, Router) {
125123
* Stop listening to route changes.
126124
*/
127125

128-
p.stop = function () {
126+
Router.prototype.stop = function () {
129127
this.history.stop()
130128
this._started = false
131129
}

src/router/internal.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ var RouteTransition = require('../transition')
55
module.exports = function (Vue, Router) {
66

77
var _ = Vue.util
8-
var p = Router.prototype
98

109
/**
1110
* Add a route containing a list of segments to the internal
@@ -17,7 +16,7 @@ module.exports = function (Vue, Router) {
1716
* @param {Array} segments
1817
*/
1918

20-
p._addRoute = function (path, handler, segments) {
19+
Router.prototype._addRoute = function (path, handler, segments) {
2120
guardComponent(handler)
2221
segments.push({
2322
path: path,
@@ -44,7 +43,7 @@ module.exports = function (Vue, Router) {
4443
* @param {Object} handler
4544
*/
4645

47-
p._notFound = function (handler) {
46+
Router.prototype._notFound = function (handler) {
4847
guardComponent(handler)
4948
this._notFoundHandler = [{ handler: handler }]
5049
}
@@ -56,7 +55,7 @@ module.exports = function (Vue, Router) {
5655
* @param {String} redirectPath
5756
*/
5857

59-
p._addRedirect = function (path, redirectPath) {
58+
Router.prototype._addRedirect = function (path, redirectPath) {
6059
this._addGuard(path, redirectPath, this.replace)
6160
}
6261

@@ -67,7 +66,7 @@ module.exports = function (Vue, Router) {
6766
* @param {String} aliasPath
6867
*/
6968

70-
p._addAlias = function (path, aliasPath) {
69+
Router.prototype._addAlias = function (path, aliasPath) {
7170
this._addGuard(path, aliasPath, this._match)
7271
}
7372

@@ -79,7 +78,7 @@ module.exports = function (Vue, Router) {
7978
* @param {Function} handler
8079
*/
8180

82-
p._addGuard = function (path, mappedPath, handler) {
81+
Router.prototype._addGuard = function (path, mappedPath, handler) {
8382
var router = this
8483
this._guardRecognizer.add([{
8584
path: path,
@@ -101,7 +100,7 @@ module.exports = function (Vue, Router) {
101100
* @return {Boolean} - if true, will skip normal match.
102101
*/
103102

104-
p._checkGuard = function (path) {
103+
Router.prototype._checkGuard = function (path) {
105104
var matched = this._guardRecognizer.recognize(path)
106105
if (matched) {
107106
matched[0].handler(matched[0], matched.queryParams)
@@ -118,7 +117,7 @@ module.exports = function (Vue, Router) {
118117
* @param {String} [anchor]
119118
*/
120119

121-
p._match = function (path, state, anchor) {
120+
Router.prototype._match = function (path, state, anchor) {
122121
var self = this
123122

124123
if (this._checkGuard(path)) {
@@ -186,7 +185,7 @@ module.exports = function (Vue, Router) {
186185
* @param {Route} route
187186
*/
188187

189-
p._updateRoute = function (route) {
188+
Router.prototype._updateRoute = function (route) {
190189
this._currentRoute = route
191190
// update route context for all children
192191
if (this.app.$route !== route) {
@@ -205,7 +204,7 @@ module.exports = function (Vue, Router) {
205204
* @param {String} [anchor]
206205
*/
207206

208-
p._postTransition = function (route, state, anchor) {
207+
Router.prototype._postTransition = function (route, state, anchor) {
209208
// handle scroll positions
210209
// saved scroll positions take priority
211210
// then we check if the path has an anchor

0 commit comments

Comments
 (0)