Throw errors when user attempts to query route before it is initialized

This commit is contained in:
Barney 2014-11-26 15:12:15 +00:00
parent f75426c8e4
commit f6a5436269

View file

@ -547,7 +547,9 @@ Mithril = m = new function app(window, undefined) {
var redirect = function() {}, routeParams = {}, currentRoute
m.route = function() {
//m.route()
if (arguments.length === 0) return currentRoute
if (arguments.length === 0) {
return checkRouteInit() && currentRoute
}
else if (arguments.length === 3 && type.call(arguments[1]) == sStr) {
var root = arguments[0], defaultRoute = arguments[1], router = arguments[2]
redirect = function(source) {
@ -592,7 +594,9 @@ Mithril = m = new function app(window, undefined) {
else window.location[m.route.mode] = currentRoute
}
}
m.route.param = function(key) {return routeParams[key]}
m.route.param = function(key) {
return checkRouteInit() && routeParams[key]
}
m.route.mode = "search"
function normalizeRoute(route) {return route.slice(modes[m.route.mode].length)}
function routeByValue(root, router, path) {
@ -655,6 +659,9 @@ Mithril = m = new function app(window, undefined) {
function decodeSpace(string) {
return decodeURIComponent(string.replace(/\+/g, " "))
}
function checkRouteInit(){
return currentRoute == null || throw "Attempted to query m.route, but m.route was not initialized";
}
function reset(root) {
var cacheKey = getCellCacheKey(root)
clear(root.childNodes, cellCache[cacheKey])