Skip to content

Commit 4ed8744

Browse files
committed
force reuse when aborting after activation
1 parent 1153cc8 commit 4ed8744

File tree

7 files changed

+21
-13
lines changed

7 files changed

+21
-13
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ npm run build
3030
# and unit tests at localhost:8081
3131
npm run dev
3232

33-
# lint & run unit tests with coverage report
33+
# lint & run all tests
3434
npm test
3535

36-
# run e2e tests for example app in Chrome & Firefox
36+
# run unit tests only
37+
npm run unit
38+
39+
# run e2e tests only
3740
npm run e2e-local
3841
```

circle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ dependencies:
1111
test:
1212
override:
1313
# Run unit tests
14-
- npm test
14+
- npm run unit
1515
# start sauce connect
1616
- cd sc-*-linux && ./bin/sc -u $SAUCE_USERNAME -k $SAUCE_ACCESS_KEY -f ~/sc_ready:
1717
background: true

example/components/inbox/message.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = {
2727
// callback based
2828
messagesSerivce.get(params, function (err, message) {
2929
if (err) {
30-
transition.abort(err)
30+
// handle error, e.g. display a warning
3131
} else {
3232
transition.next({
3333
message: message

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
"scripts": {
77
"dev": "npm run serve & npm run serve-test",
88
"lint": "eslint src build test/e2e test/unit/specs",
9-
"test": "npm run lint && ./node_modules/karma/bin/karma start build/karma.config.js",
9+
"unit": "./node_modules/karma/bin/karma start build/karma.config.js",
1010
"build": "webpack --config build/webpack.build.dev.config.js && webpack --config build/webpack.build.min.config.js",
1111
"serve": "webpack-dev-server --hot --config example/webpack.config.js --content-base example --history-api-fallback --host 0.0.0.0",
1212
"serve-test": "webpack-dev-server --quiet --config test/unit/webpack.config.js --content-base test/unit --history-api-fallback --host 0.0.0.0 --port 8081",
1313
"e2e-sauce": "nightwatch -c build/nightwatch.sauce.json -e chrome,firefox,ie10,ie11",
1414
"e2e-local": "bash ./build/e2e.sh",
1515
"release": "bash ./build/release.sh",
16-
"docs": "bash ./build/update-docs.sh"
16+
"docs": "bash ./build/update-docs.sh",
17+
"test": "npm run lint && npm run unit && npm run e2e-local"
1718
},
1819
"repository": {
1920
"type": "git",

src/directives/view.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ module.exports = function (Vue) {
3838
// in the router. actual component switching will be
3939
// managed by the pipeline.
4040
var router = this.router = route._router
41-
this.depth = router._views.length
4241
router._views.unshift(this)
4342

4443
// note the views are in reverse order.

src/pipeline.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ exports.canReuse = function (view, handler, transition) {
1313
if (!component || !handler) {
1414
return false
1515
}
16-
if (component.constructor !== handler.component) {
16+
// important: check view.Component here because it may
17+
// have been changed in activate hook
18+
if (view.Component !== handler.component) {
1719
return false
1820
}
1921
var canReuseFn = util.getRouteConfig(component, 'canReuse')
@@ -92,11 +94,12 @@ exports.deactivate = function (view, transition, next) {
9294
*
9395
* @param {Directive} view
9496
* @param {Transition} transition
97+
* @param {Number} depth
9598
* @param {Function} [cb]
9699
*/
97100

98-
exports.activate = function (view, transition, cb) {
99-
var handler = transition.activateQueue[view.depth]
101+
exports.activate = function (view, transition, depth, cb) {
102+
var handler = transition.activateQueue[depth]
100103
if (!handler) {
101104
view.setComponent(null)
102105
cb && cb()
@@ -143,7 +146,7 @@ exports.activate = function (view, transition, cb) {
143146
var afterActivate = function () {
144147
// activate the child view
145148
if (view.childView) {
146-
exports.activate(view.childView, transition)
149+
exports.activate(view.childView, transition, depth + 1)
147150
}
148151
if (dataHook && waitForData) {
149152
// wait until data loaded to insert

src/transition.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ p.start = function (cb) {
136136
// the root of the chain that needs to be replaced
137137
// is the top-most non-reusable view.
138138
if (daq.length) {
139-
pipeline.activate(daq[daq.length - 1], transition, cb)
139+
var view = daq[daq.length - 1]
140+
var depth = reuseQueue ? reuseQueue.length : 0
141+
pipeline.activate(view, transition, depth, cb)
140142
} else {
141143
cb()
142144
}
@@ -194,8 +196,8 @@ p.callHook = function (hook, context, cb, expectBoolean, cleanup) {
194196
cb(data)
195197
}
196198
var abort = function () {
197-
transition.abort()
198199
cleanup && cleanup()
200+
transition.abort()
199201
}
200202
// the copied transition object passed to the user.
201203
var exposed = {

0 commit comments

Comments
 (0)