Skip to content

Commit 39c2ded

Browse files
committed
[build] 0.7.2
1 parent 29f833e commit 39c2ded

File tree

2 files changed

+116
-77
lines changed

2 files changed

+116
-77
lines changed

dist/vue-router.js

Lines changed: 114 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* vue-router v0.7.1
2+
* vue-router v0.7.2
33
* (c) 2015 Evan You
44
* Released under the MIT License.
55
*/
@@ -71,9 +71,9 @@ return /******/ (function(modules) { // webpackBootstrap
7171

7272
var _util2 = _interopRequireDefault(_util);
7373

74-
var _mixin = __webpack_require__(7);
74+
var _override = __webpack_require__(7);
7575

76-
var _mixin2 = _interopRequireDefault(_mixin);
76+
var _override2 = _interopRequireDefault(_override);
7777

7878
var _routeRecognizer = __webpack_require__(4);
7979

@@ -517,7 +517,9 @@ return /******/ (function(modules) { // webpackBootstrap
517517
if (beforeHooks.length) {
518518
transition.runQueue(beforeHooks, function (hook, _, next) {
519519
if (transition === _this2._currentTransition) {
520-
transition.callHook(hook, null, next, true);
520+
transition.callHook(hook, null, next, {
521+
expectBoolean: true
522+
});
521523
}
522524
}, startTransition);
523525
} else {
@@ -655,7 +657,7 @@ return /******/ (function(modules) { // webpackBootstrap
655657
return;
656658
}
657659
Vue = externalVue;
658-
_mixin2['default'](Vue);
660+
_override2['default'](Vue);
659661
_directivesView2['default'](Vue);
660662
_directivesLink2['default'](Vue);
661663
_util2['default'].Vue = Vue;
@@ -1565,53 +1567,37 @@ return /******/ (function(modules) { // webpackBootstrap
15651567
exports['default'] = function (Vue) {
15661568

15671569
var _ = Vue.util;
1568-
var mixin = {
1569-
init: function init() {
1570-
var route = this.$root.$route;
1571-
if (route) {
1572-
route.router._children.push(this);
1573-
if (!this.$route) {
1570+
1571+
var init = Vue.prototype._init;
1572+
Vue.prototype._init = function (options) {
1573+
var root = options._parent || options.parent || this;
1574+
var route = root.$route;
1575+
if (route) {
1576+
route.router._children.push(this);
1577+
if (!this.$route) {
1578+
/* istanbul ignore if */
1579+
if (this._defineMeta) {
1580+
// 0.12
1581+
this._defineMeta('$route', route);
1582+
} else {
1583+
// 1.0
15741584
_.defineReactive(this, '$route', route);
15751585
}
15761586
}
1577-
},
1578-
beforeDestroy: function beforeDestroy() {
1587+
}
1588+
init.call(this, options);
1589+
};
1590+
1591+
var destroy = Vue.prototype._destroy;
1592+
Vue.prototype._destroy = function () {
1593+
if (!this._isBeingDestroyed) {
15791594
var route = this.$root.$route;
15801595
if (route) {
15811596
route.router._children.$remove(this);
15821597
}
1598+
destroy.apply(this, arguments);
15831599
}
15841600
};
1585-
1586-
// pre 1.0.0-rc compat
1587-
if (!Vue.config.optionMergeStrategies || !Vue.config.optionMergeStrategies.init) {
1588-
(function () {
1589-
delete mixin.init;
1590-
var init = Vue.prototype._init;
1591-
Vue.prototype._init = function (options) {
1592-
var root = options._parent || options.parent || this;
1593-
var route = root.$route;
1594-
if (route) {
1595-
route.router._children.push(this);
1596-
if (!this.$route) {
1597-
if (this._defineMeta) {
1598-
this._defineMeta('$route', route);
1599-
} else {
1600-
_.defineReactive(this, '$route', route);
1601-
}
1602-
}
1603-
}
1604-
init.call(this, options);
1605-
};
1606-
})();
1607-
}
1608-
1609-
if (Vue.mixin) {
1610-
Vue.mixin(mixin);
1611-
} else {
1612-
// 0.12 compat
1613-
Vue.options = _.mergeOptions(Vue.options, mixin);
1614-
}
16151601
};
16161602

16171603
module.exports = exports['default'];
@@ -1996,6 +1982,9 @@ return /******/ (function(modules) { // webpackBootstrap
19961982
* Call a user provided route transition hook and handle
19971983
* the response (e.g. if the user returns a promise).
19981984
*
1985+
* If the user neither expects an argument nor returns a
1986+
* promise, the hook is assumed to be synchronous.
1987+
*
19991988
* @param {Function} hook
20001989
* @param {*} [context]
20011990
* @param {Function} [cb]
@@ -2078,10 +2067,12 @@ return /******/ (function(modules) { // webpackBootstrap
20782067
res.then(function (ok) {
20792068
ok ? next() : abort();
20802069
}, onError);
2070+
} else if (!hook.length) {
2071+
next(res);
20812072
}
20822073
} else if (resIsPromise) {
20832074
res.then(next, onError);
2084-
} else if (expectData && isPlainOjbect(res)) {
2075+
} else if (expectData && isPlainOjbect(res) || !hook.length) {
20852076
next(res);
20862077
}
20872078
};
@@ -2212,7 +2203,7 @@ return /******/ (function(modules) { // webpackBootstrap
22122203
* @param {Function} [cb]
22132204
*/
22142205

2215-
function activate(view, transition, depth, cb) {
2206+
function activate(view, transition, depth, cb, reuse) {
22162207
var handler = transition.activateQueue[depth];
22172208
if (!handler) {
22182209
// fix 1.0.0-alpha.3 compat
@@ -2231,17 +2222,61 @@ return /******/ (function(modules) { // webpackBootstrap
22312222
view.depth = depth;
22322223
view.activated = false;
22332224

2234-
// unbuild current component. this step also destroys
2235-
// and removes all nested child views.
2236-
view.unbuild(true);
2237-
// build the new component. this will also create the
2238-
// direct child view of the current one. it will register
2239-
// itself as view.childView.
2240-
var component = view.build({
2241-
_meta: {
2242-
$loadingRouteData: !!(dataHook && !waitForData)
2225+
var component = undefined;
2226+
var loading = !!(dataHook && !waitForData);
2227+
2228+
// "reuse" is a flag passed down when the parent view is
2229+
// either reused via keep-alive or as a child of a kept-alive view.
2230+
// of course we can only reuse if the current kept-alive instance
2231+
// is of the correct type.
2232+
reuse = reuse && view.childVM && view.childVM.constructor === Component;
2233+
2234+
if (reuse) {
2235+
// just reuse
2236+
component = view.childVM;
2237+
component.$loadingRouteData = loading;
2238+
} else {
2239+
// unbuild current component. this step also destroys
2240+
// and removes all nested child views.
2241+
view.unbuild(true);
2242+
// handle keep-alive.
2243+
// if the view has keep-alive, the child vm is not actually
2244+
// destroyed - its nested views will still be in router's
2245+
// view list. We need to removed these child views and
2246+
// cache them on the child vm.
2247+
if (view.keepAlive) {
2248+
var views = transition.router._views;
2249+
var i = views.indexOf(view);
2250+
if (i > 0) {
2251+
transition.router._views = views.slice(i);
2252+
if (view.childVM) {
2253+
view.childVM._routerViews = views.slice(0, i);
2254+
}
2255+
}
2256+
}
2257+
2258+
// build the new component. this will also create the
2259+
// direct child view of the current one. it will register
2260+
// itself as view.childView.
2261+
component = view.build({
2262+
_meta: {
2263+
$loadingRouteData: loading
2264+
}
2265+
});
2266+
// handle keep-alive.
2267+
// when a kept-alive child vm is restored, we need to
2268+
// add its cached child views into the router's view list,
2269+
// and also properly update current view's child view.
2270+
if (view.keepAlive) {
2271+
component.$loadingRouteData = loading;
2272+
var cachedViews = component._routerViews;
2273+
if (cachedViews) {
2274+
transition.router._views = cachedViews.concat(transition.router._views);
2275+
view.childView = cachedViews[cachedViews.length - 1];
2276+
component._routerViews = null;
2277+
}
22432278
}
2244-
});
2279+
}
22452280

22462281
// cleanup the component in case the transition is aborted
22472282
// before the component is ever inserted.
@@ -2251,11 +2286,16 @@ return /******/ (function(modules) { // webpackBootstrap
22512286

22522287
// actually insert the component and trigger transition
22532288
var insert = function insert() {
2289+
if (reuse) {
2290+
cb && cb();
2291+
return;
2292+
}
22542293
var router = transition.router;
22552294
if (router._rendered || router._transitionOnLoad) {
22562295
view.transition(component);
22572296
} else {
22582297
// no transition on first render, manual transition
2298+
/* istanbul ignore if */
22592299
if (view.setCurrent) {
22602300
// 0.12 compat
22612301
view.setCurrent(component);
@@ -2273,7 +2313,7 @@ return /******/ (function(modules) { // webpackBootstrap
22732313
view.activated = true;
22742314
// activate the child view
22752315
if (view.childView) {
2276-
activate(view.childView, transition, depth + 1);
2316+
activate(view.childView, transition, depth + 1, null, reuse || view.keepAlive);
22772317
}
22782318
if (dataHook && waitForData) {
22792319
// wait until data loaded to insert
@@ -2325,24 +2365,27 @@ return /******/ (function(modules) { // webpackBootstrap
23252365
component.$loadingRouteData = true;
23262366
transition.callHook(hook, component, function (data, onError) {
23272367
var promises = [];
2328-
_Object$keys(data).forEach(function (key) {
2329-
var val = data[key];
2330-
if (_util.isPromise(val)) {
2331-
promises.push(val.then(function (resolvedVal) {
2332-
component.$set(key, resolvedVal);
2333-
}));
2334-
} else {
2335-
component.$set(key, val);
2336-
}
2337-
});
2368+
if (Object.prototype.toString.call(data) === '[object Object]') {
2369+
_Object$keys(data).forEach(function (key) {
2370+
var val = data[key];
2371+
if (_util.isPromise(val)) {
2372+
promises.push(val.then(function (resolvedVal) {
2373+
component.$set(key, resolvedVal);
2374+
}));
2375+
} else {
2376+
component.$set(key, val);
2377+
}
2378+
});
2379+
}
23382380
if (!promises.length) {
23392381
component.$loadingRouteData = false;
2382+
cb && cb();
23402383
} else {
23412384
promises[0].constructor.all(promises).then(function (_) {
23422385
component.$loadingRouteData = false;
2386+
cb && cb();
23432387
}, onError);
23442388
}
2345-
cb && cb(data);
23462389
}, {
23472390
cleanup: cleanup,
23482391
expectData: true
@@ -2436,13 +2479,6 @@ return /******/ (function(modules) { // webpackBootstrap
24362479
// finally, init by delegating to v-component
24372480
componentDef.bind.call(this);
24382481

2439-
// does not support keep-alive.
2440-
/* istanbul ignore if */
2441-
if (this.keepAlive) {
2442-
this.keepAlive = false;
2443-
_util.warn('<router-view> does not support keep-alive.');
2444-
}
2445-
24462482
// all we need to do here is registering this view
24472483
// in the router. actual component switching will be
24482484
// managed by the pipeline.
@@ -2493,6 +2529,7 @@ return /******/ (function(modules) { // webpackBootstrap
24932529

24942530
var _util = __webpack_require__(3);
24952531

2532+
var trailingSlashRE = /\/$/;
24962533
var regexEscapeRE = /[-.*+?^${}()|[\]\/\\]/g;
24972534

24982535
// install v-link, which provides navigation support for
@@ -2587,7 +2624,9 @@ return /******/ (function(modules) { // webpackBootstrap
25872624
}
25882625
// add new class
25892626
if (this.exact) {
2590-
if (path === dest) {
2627+
if (dest === path ||
2628+
// also allow additional trailing slash
2629+
dest.charAt(dest.length - 1) !== '/' && dest === path.replace(trailingSlashRE, '')) {
25912630
_.addClass(el, activeClass);
25922631
} else {
25932632
_.removeClass(el, activeClass);

0 commit comments

Comments
 (0)