Skip to content

Commit cb575e8

Browse files
committed
[build] 0.7.3
1 parent 3381256 commit cb575e8

File tree

2 files changed

+155
-43
lines changed

2 files changed

+155
-43
lines changed

dist/vue-router.js

Lines changed: 153 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* vue-router v0.7.2
2+
* vue-router v0.7.3
33
* (c) 2015 Evan You
44
* Released under the MIT License.
55
*/
@@ -87,23 +87,23 @@ return /******/ (function(modules) { // webpackBootstrap
8787

8888
var _transition2 = _interopRequireDefault(_transition);
8989

90-
var _directivesView = __webpack_require__(25);
90+
var _directivesView = __webpack_require__(28);
9191

9292
var _directivesView2 = _interopRequireDefault(_directivesView);
9393

94-
var _directivesLink = __webpack_require__(26);
94+
var _directivesLink = __webpack_require__(29);
9595

9696
var _directivesLink2 = _interopRequireDefault(_directivesLink);
9797

98-
var _historyAbstract = __webpack_require__(27);
98+
var _historyAbstract = __webpack_require__(30);
9999

100100
var _historyAbstract2 = _interopRequireDefault(_historyAbstract);
101101

102-
var _historyHash = __webpack_require__(28);
102+
var _historyHash = __webpack_require__(31);
103103

104104
var _historyHash2 = _interopRequireDefault(_historyHash);
105105

106-
var _historyHtml5 = __webpack_require__(29);
106+
var _historyHtml5 = __webpack_require__(32);
107107

108108
var _historyHtml52 = _interopRequireDefault(_historyHtml5);
109109

@@ -478,22 +478,34 @@ return /******/ (function(modules) { // webpackBootstrap
478478
return;
479479
}
480480

481-
var prevRoute = this._currentRoute;
482-
var prevTransition = this._currentTransition;
481+
var currentRoute = this._currentRoute;
482+
var currentTransition = this._currentTransition;
483483

484-
// do nothing if going to the same route.
485-
// the route only changes when a transition successfully
486-
// reaches activation; we don't need to do anything
487-
// if an ongoing transition is aborted during validation
488-
// phase.
489-
if (prevTransition && path === prevRoute.path) {
490-
return;
484+
if (currentTransition) {
485+
if (currentTransition.to.path === path) {
486+
// do nothing if we have an active transition going to the same path
487+
return;
488+
} else if (currentRoute.path === path) {
489+
// We are going to the same path, but we also have an ongoing but
490+
// not-yet-validated transition. Abort that transition and reset to
491+
// prev transition.
492+
currentTransition.aborted = true;
493+
this._currentTransition = this._prevTransition;
494+
return;
495+
} else {
496+
// going to a totally different path. abort ongoing transition.
497+
currentTransition.aborted = true;
498+
}
491499
}
492500

493501
// construct new route and transition context
494502
var route = new _route2['default'](path, this);
495-
var transition = new _transition2['default'](this, route, prevRoute);
496-
this._prevTransition = prevTransition;
503+
var transition = new _transition2['default'](this, route, currentRoute);
504+
505+
// current transition is updated right now.
506+
// however, current route will only be updated after the transition has
507+
// been validated.
508+
this._prevTransition = currentTransition;
497509
this._currentTransition = transition;
498510

499511
if (!this.app) {
@@ -546,12 +558,6 @@ return /******/ (function(modules) { // webpackBootstrap
546558
*/
547559

548560
Router.prototype._onTransitionValidated = function _onTransitionValidated(transition) {
549-
// now that this one is validated, we can abort
550-
// the previous transition.
551-
var prevTransition = this._prevTransition;
552-
if (prevTransition) {
553-
prevTransition.aborted = true;
554-
}
555561
// set current route
556562
var route = this._currentRoute = transition.to;
557563
// update route context for all children
@@ -661,12 +667,6 @@ return /******/ (function(modules) { // webpackBootstrap
661667
_directivesView2['default'](Vue);
662668
_directivesLink2['default'](Vue);
663669
_util2['default'].Vue = Vue;
664-
// 1.0 only: enable route mixins
665-
var strats = Vue.config.optionMergeStrategies;
666-
if (strats) {
667-
// use the same merge strategy as methods (object hash)
668-
strats.route = strats.methods;
669-
}
670670
Router.installed = true;
671671
};
672672

@@ -1568,6 +1568,7 @@ return /******/ (function(modules) { // webpackBootstrap
15681568

15691569
var _ = Vue.util;
15701570

1571+
// override Vue's init and destroy process to keep track of router instances
15711572
var init = Vue.prototype._init;
15721573
Vue.prototype._init = function (options) {
15731574
var root = options._parent || options.parent || this;
@@ -1598,6 +1599,31 @@ return /******/ (function(modules) { // webpackBootstrap
15981599
destroy.apply(this, arguments);
15991600
}
16001601
};
1602+
1603+
// 1.0 only: enable route mixins
1604+
var strats = Vue.config.optionMergeStrategies;
1605+
var hooksToMergeRE = /^(data|activate|deactivate)$/;
1606+
1607+
if (strats) {
1608+
strats.route = function (parentVal, childVal) {
1609+
if (!childVal) return parentVal;
1610+
if (!parentVal) return childVal;
1611+
var ret = {};
1612+
_.extend(ret, parentVal);
1613+
for (var key in childVal) {
1614+
var a = ret[key];
1615+
var b = childVal[key];
1616+
// for data, activate and deactivate, we need to merge them into
1617+
// arrays similar to lifecycle hooks.
1618+
if (a && hooksToMergeRE.test(key)) {
1619+
ret[key] = (_.isArray(a) ? a : [a]).concat(b);
1620+
} else {
1621+
ret[key] = b;
1622+
}
1623+
}
1624+
return ret;
1625+
};
1626+
}
16011627
};
16021628

16031629
module.exports = exports['default'];
@@ -2007,9 +2033,9 @@ return /******/ (function(modules) { // webpackBootstrap
20072033
var nextCalled = false;
20082034

20092035
// abort the transition
2010-
var abort = function abort(back) {
2036+
var abort = function abort() {
20112037
cleanup && cleanup();
2012-
transition.abort(back);
2038+
transition.abort();
20132039
};
20142040

20152041
// handle errors
@@ -2031,10 +2057,11 @@ return /******/ (function(modules) { // webpackBootstrap
20312057
return;
20322058
}
20332059
nextCalled = true;
2034-
if (!cb || transition.aborted) {
2060+
if (transition.aborted) {
2061+
cleanup && cleanup();
20352062
return;
20362063
}
2037-
cb(data, onError);
2064+
cb && cb(data, onError);
20382065
};
20392066

20402067
// expose a clone of the transition object, so that each
@@ -2077,6 +2104,40 @@ return /******/ (function(modules) { // webpackBootstrap
20772104
}
20782105
};
20792106

2107+
/**
2108+
* Call a single hook or an array of async hooks in series.
2109+
*
2110+
* @param {Array} hooks
2111+
* @param {*} context
2112+
* @param {Function} cb
2113+
* @param {Object} [options]
2114+
*/
2115+
2116+
RouteTransition.prototype.callHooks = function callHooks(hooks, context, cb, options) {
2117+
var _this = this;
2118+
2119+
if (Array.isArray(hooks)) {
2120+
(function () {
2121+
var res = [];
2122+
res._needMerge = true;
2123+
var onError = undefined;
2124+
_this.runQueue(hooks, function (hook, _, next) {
2125+
if (!_this.aborted) {
2126+
_this.callHook(hook, context, function (r, onError) {
2127+
if (r) res.push(r);
2128+
onError = onError;
2129+
next();
2130+
}, options);
2131+
}
2132+
}, function () {
2133+
cb(res, onError);
2134+
});
2135+
})();
2136+
} else {
2137+
this.callHook(hooks, context, cb, options);
2138+
}
2139+
};
2140+
20802141
return RouteTransition;
20812142
})();
20822143

@@ -2095,6 +2156,8 @@ return /******/ (function(modules) { // webpackBootstrap
20952156

20962157
var _Object$keys = __webpack_require__(20)['default'];
20972158

2159+
var _Object$create = __webpack_require__(25)['default'];
2160+
20982161
exports.__esModule = true;
20992162
exports.canReuse = canReuse;
21002163
exports.canDeactivate = canDeactivate;
@@ -2190,7 +2253,7 @@ return /******/ (function(modules) { // webpackBootstrap
21902253
if (!hook) {
21912254
next();
21922255
} else {
2193-
transition.callHook(hook, component, next);
2256+
transition.callHooks(hook, component, next);
21942257
}
21952258
}
21962259

@@ -2328,7 +2391,7 @@ return /******/ (function(modules) { // webpackBootstrap
23282391
};
23292392

23302393
if (activateHook) {
2331-
transition.callHook(activateHook, component, afterActivate, {
2394+
transition.callHooks(activateHook, component, afterActivate, {
23322395
cleanup: cleanup
23332396
});
23342397
} else {
@@ -2363,9 +2426,21 @@ return /******/ (function(modules) { // webpackBootstrap
23632426

23642427
function loadData(component, transition, hook, cb, cleanup) {
23652428
component.$loadingRouteData = true;
2366-
transition.callHook(hook, component, function (data, onError) {
2429+
transition.callHooks(hook, component, function (data, onError) {
2430+
// merge data from multiple data hooks
2431+
if (Array.isArray(data) && data._needMerge) {
2432+
data = data.reduce(function (res, obj) {
2433+
if (isPlainObject(obj)) {
2434+
_Object$keys(obj).forEach(function (key) {
2435+
res[key] = obj[key];
2436+
});
2437+
}
2438+
return res;
2439+
}, _Object$create(null));
2440+
}
2441+
// handle promise sugar syntax
23672442
var promises = [];
2368-
if (Object.prototype.toString.call(data) === '[object Object]') {
2443+
if (isPlainObject(data)) {
23692444
_Object$keys(data).forEach(function (key) {
23702445
var val = data[key];
23712446
if (_util.isPromise(val)) {
@@ -2392,6 +2467,10 @@ return /******/ (function(modules) { // webpackBootstrap
23922467
});
23932468
}
23942469

2470+
function isPlainObject(obj) {
2471+
return Object.prototype.toString.call(obj) === '[object Object]';
2472+
}
2473+
23952474
/***/ },
23962475
/* 20 */
23972476
/***/ function(module, exports, __webpack_require__) {
@@ -2440,6 +2519,39 @@ return /******/ (function(modules) { // webpackBootstrap
24402519

24412520
/***/ },
24422521
/* 25 */
2522+
/***/ function(module, exports, __webpack_require__) {
2523+
2524+
module.exports = { "default": __webpack_require__(26), __esModule: true };
2525+
2526+
/***/ },
2527+
/* 26 */
2528+
/***/ function(module, exports, __webpack_require__) {
2529+
2530+
var $ = __webpack_require__(27);
2531+
module.exports = function create(P, D){
2532+
return $.create(P, D);
2533+
};
2534+
2535+
/***/ },
2536+
/* 27 */
2537+
/***/ function(module, exports) {
2538+
2539+
var $Object = Object;
2540+
module.exports = {
2541+
create: $Object.create,
2542+
getProto: $Object.getPrototypeOf,
2543+
isEnum: {}.propertyIsEnumerable,
2544+
getDesc: $Object.getOwnPropertyDescriptor,
2545+
setDesc: $Object.defineProperty,
2546+
setDescs: $Object.defineProperties,
2547+
getKeys: $Object.keys,
2548+
getNames: $Object.getOwnPropertyNames,
2549+
getSymbols: $Object.getOwnPropertySymbols,
2550+
each: [].forEach
2551+
};
2552+
2553+
/***/ },
2554+
/* 28 */
24432555
/***/ function(module, exports, __webpack_require__) {
24442556

24452557
'use strict';
@@ -2520,7 +2632,7 @@ return /******/ (function(modules) { // webpackBootstrap
25202632
module.exports = exports['default'];
25212633

25222634
/***/ },
2523-
/* 26 */
2635+
/* 29 */
25242636
/***/ function(module, exports, __webpack_require__) {
25252637

25262638
'use strict';
@@ -2654,7 +2766,7 @@ return /******/ (function(modules) { // webpackBootstrap
26542766
module.exports = exports['default'];
26552767

26562768
/***/ },
2657-
/* 27 */
2769+
/* 30 */
26582770
/***/ function(module, exports, __webpack_require__) {
26592771

26602772
'use strict';
@@ -2699,7 +2811,7 @@ return /******/ (function(modules) { // webpackBootstrap
26992811
module.exports = exports['default'];
27002812

27012813
/***/ },
2702-
/* 28 */
2814+
/* 31 */
27032815
/***/ function(module, exports, __webpack_require__) {
27042816

27052817
'use strict';
@@ -2768,7 +2880,7 @@ return /******/ (function(modules) { // webpackBootstrap
27682880
module.exports = exports['default'];
27692881

27702882
/***/ },
2771-
/* 29 */
2883+
/* 32 */
27722884
/***/ function(module, exports, __webpack_require__) {
27732885

27742886
'use strict';

0 commit comments

Comments
 (0)