Skip to content

Commit 7e8060a

Browse files
committed
[build] 0.7.11
1 parent e9e3dbf commit 7e8060a

File tree

2 files changed

+99
-84
lines changed

2 files changed

+99
-84
lines changed

dist/vue-router.js

Lines changed: 97 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* vue-router v0.7.10
2+
* vue-router v0.7.11
33
* (c) 2016 Evan You
44
* Released under the MIT License.
55
*/
@@ -911,7 +911,7 @@
911911
x: window.pageXOffset,
912912
y: window.pageYOffset
913913
}
914-
}, '');
914+
}, '', location.href);
915915
// then push new state
916916
history.pushState({}, '', url);
917917
}
@@ -1236,7 +1236,10 @@
12361236
};
12371237

12381238
if (activateHook) {
1239-
transition.callHooks(activateHook, component, afterActivate, { cleanup: cleanup });
1239+
transition.callHooks(activateHook, component, afterActivate, {
1240+
cleanup: cleanup,
1241+
postActivate: true
1242+
});
12401243
} else {
12411244
afterActivate();
12421245
}
@@ -1269,46 +1272,32 @@
12691272

12701273
function loadData(component, transition, hook, cb, cleanup) {
12711274
component.$loadingRouteData = true;
1272-
transition.callHooks(hook, component, function (data, onError) {
1273-
// merge data from multiple data hooks
1274-
if (Array.isArray(data) && data._needMerge) {
1275-
data = data.reduce(function (res, obj) {
1276-
if (isPlainObject(obj)) {
1277-
Object.keys(obj).forEach(function (key) {
1278-
res[key] = obj[key];
1279-
});
1280-
}
1281-
return res;
1282-
}, Object.create(null));
1283-
}
1284-
// handle promise sugar syntax
1285-
var promises = [];
1286-
if (isPlainObject(data)) {
1287-
Object.keys(data).forEach(function (key) {
1288-
var val = data[key];
1289-
if (isPromise(val)) {
1290-
promises.push(val.then(function (resolvedVal) {
1291-
component.$set(key, resolvedVal);
1292-
}));
1293-
} else {
1294-
component.$set(key, val);
1295-
}
1296-
});
1297-
}
1298-
if (!promises.length) {
1299-
component.$loadingRouteData = false;
1300-
component.$emit('route-data-loaded', component);
1301-
cb && cb();
1302-
} else {
1303-
promises[0].constructor.all(promises).then(function () {
1304-
component.$loadingRouteData = false;
1305-
component.$emit('route-data-loaded', component);
1306-
cb && cb();
1307-
}, onError);
1308-
}
1275+
transition.callHooks(hook, component, function () {
1276+
component.$loadingRouteData = false;
1277+
component.$emit('route-data-loaded', component);
1278+
cb && cb();
13091279
}, {
13101280
cleanup: cleanup,
1311-
expectData: true
1281+
postActivate: true,
1282+
processData: function processData(data) {
1283+
// handle promise sugar syntax
1284+
var promises = [];
1285+
if (isPlainObject(data)) {
1286+
Object.keys(data).forEach(function (key) {
1287+
var val = data[key];
1288+
if (isPromise(val)) {
1289+
promises.push(val.then(function (resolvedVal) {
1290+
component.$set(key, resolvedVal);
1291+
}));
1292+
} else {
1293+
component.$set(key, val);
1294+
}
1295+
});
1296+
}
1297+
if (promises.length) {
1298+
return promises[0].constructor.all(promises);
1299+
}
1300+
}
13121301
});
13131302
}
13141303

@@ -1518,7 +1507,8 @@
15181507
* @param {Function} [cb]
15191508
* @param {Object} [options]
15201509
* - {Boolean} expectBoolean
1521-
* - {Boolean} expectData
1510+
* - {Boolean} postActive
1511+
* - {Function} processData
15221512
* - {Function} cleanup
15231513
*/
15241514

@@ -1527,8 +1517,9 @@
15271517

15281518
var _ref$expectBoolean = _ref.expectBoolean;
15291519
var expectBoolean = _ref$expectBoolean === undefined ? false : _ref$expectBoolean;
1530-
var _ref$expectData = _ref.expectData;
1531-
var expectData = _ref$expectData === undefined ? false : _ref$expectData;
1520+
var _ref$postActivate = _ref.postActivate;
1521+
var postActivate = _ref$postActivate === undefined ? false : _ref$postActivate;
1522+
var processData = _ref.processData;
15321523
var cleanup = _ref.cleanup;
15331524

15341525
var transition = this;
@@ -1542,18 +1533,27 @@
15421533

15431534
// handle errors
15441535
var onError = function onError(err) {
1545-
// cleanup indicates an after-activation hook,
1546-
// so instead of aborting we just let the transition
1547-
// finish.
1548-
cleanup ? next() : abort();
1536+
postActivate ? next() : abort();
15491537
if (err && !transition.router._suppress) {
15501538
warn('Uncaught error during transition: ');
15511539
throw err instanceof Error ? err : new Error(err);
15521540
}
15531541
};
15541542

1543+
// since promise swallows errors, we have to
1544+
// throw it in the next tick...
1545+
var onPromiseError = function onPromiseError(err) {
1546+
try {
1547+
onError(err);
1548+
} catch (e) {
1549+
setTimeout(function () {
1550+
throw e;
1551+
}, 0);
1552+
}
1553+
};
1554+
15551555
// advance the transition to the next step
1556-
var next = function next(data) {
1556+
var next = function next() {
15571557
if (nextCalled) {
15581558
warn('transition.next() should be called only once.');
15591559
return;
@@ -1563,7 +1563,33 @@
15631563
cleanup && cleanup();
15641564
return;
15651565
}
1566-
cb && cb(data, onError);
1566+
cb && cb();
1567+
};
1568+
1569+
var nextWithBoolean = function nextWithBoolean(res) {
1570+
if (typeof res === 'boolean') {
1571+
res ? next() : abort();
1572+
} else if (isPromise(res)) {
1573+
res.then(function (ok) {
1574+
ok ? next() : abort();
1575+
}, onPromiseError);
1576+
} else if (!hook.length) {
1577+
next();
1578+
}
1579+
};
1580+
1581+
var nextWithData = function nextWithData(data) {
1582+
var res = undefined;
1583+
try {
1584+
res = processData(data);
1585+
} catch (err) {
1586+
return onError(err);
1587+
}
1588+
if (isPromise(res)) {
1589+
res.then(next, onPromiseError);
1590+
} else {
1591+
next();
1592+
}
15671593
};
15681594

15691595
// expose a clone of the transition object, so that each
@@ -1573,7 +1599,7 @@
15731599
to: transition.to,
15741600
from: transition.from,
15751601
abort: abort,
1576-
next: next,
1602+
next: processData ? nextWithData : next,
15771603
redirect: function redirect() {
15781604
transition.redirect.apply(transition, arguments);
15791605
}
@@ -1587,22 +1613,21 @@
15871613
return onError(err);
15881614
}
15891615

1590-
// handle boolean/promise return values
1591-
var resIsPromise = isPromise(res);
15921616
if (expectBoolean) {
1593-
if (typeof res === 'boolean') {
1594-
res ? next() : abort();
1595-
} else if (resIsPromise) {
1596-
res.then(function (ok) {
1597-
ok ? next() : abort();
1598-
}, onError);
1599-
} else if (!hook.length) {
1600-
next(res);
1617+
// boolean hooks
1618+
nextWithBoolean(res);
1619+
} else if (isPromise(res)) {
1620+
// promise
1621+
if (processData) {
1622+
res.then(nextWithData, onPromiseError);
1623+
} else {
1624+
res.then(next, onPromiseError);
16011625
}
1602-
} else if (resIsPromise) {
1603-
res.then(next, onError);
1604-
} else if (expectData && isPlainOjbect(res) || !hook.length) {
1605-
next(res);
1626+
} else if (processData && isPlainOjbect(res)) {
1627+
// data promise sugar
1628+
nextWithData(res);
1629+
} else if (!hook.length) {
1630+
next();
16061631
}
16071632
};
16081633

@@ -1619,22 +1644,11 @@
16191644
var _this = this;
16201645

16211646
if (Array.isArray(hooks)) {
1622-
(function () {
1623-
var res = [];
1624-
res._needMerge = true;
1625-
var onError = undefined;
1626-
_this.runQueue(hooks, function (hook, _, next) {
1627-
if (!_this.aborted) {
1628-
_this.callHook(hook, context, function (r, onError) {
1629-
if (r) res.push(r);
1630-
onError = onError;
1631-
next();
1632-
}, options);
1633-
}
1634-
}, function () {
1635-
cb(res, onError);
1636-
});
1637-
})();
1647+
this.runQueue(hooks, function (hook, _, next) {
1648+
if (!_this.aborted) {
1649+
_this.callHook(hook, context, next, options);
1650+
}
1651+
}, cb);
16381652
} else {
16391653
this.callHook(hooks, context, cb, options);
16401654
}
@@ -1884,7 +1898,8 @@
18841898
return;
18851899
}
18861900
// handle click
1887-
this.el.addEventListener('click', _bind(this.onClick, this));
1901+
this.handler = _bind(this.onClick, this);
1902+
this.el.addEventListener('click', this.handler);
18881903
},
18891904

18901905
update: function update(target) {

0 commit comments

Comments
 (0)