diff --git a/README.md b/README.md index 9ddad4bf..4d6e53b3 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,6 @@ There are over 4000 assertions in the test suite, and tests cover even difficult ## Modularity -Despite the huge improvements in performance and modularity, the new codebase is smaller than v0.2.x, currently clocking at 7.41 KB min+gzip +Despite the huge improvements in performance and modularity, the new codebase is smaller than v0.2.x, currently clocking at 7.46 KB min+gzip In addition, Mithril is now completely modular: you can import only the modules that you need and easily integrate 3rd party modules if you wish to use a different library for routing, ajax, and even rendering diff --git a/mithril.js b/mithril.js index 64a76fb6..e3c8b8e0 100644 --- a/mithril.js +++ b/mithril.js @@ -1092,11 +1092,11 @@ var coreRouter = function($window) { var _20 = function($window, redrawService0) { var routeService = coreRouter($window) var identity = function(v) {return v} - var render1, component, attrs3, currentPath + var routing = false, render1, component, attrs3, currentPath, resolve var route = function(root, defaultRoute, routes) { if (root == null) throw new Error("Ensure the DOM element that was passed to `m.route` is not undefined") var update = function(routeResolver, comp, params, path) { - component = comp || "div", attrs3 = params, currentPath = path + component = comp || "div", attrs3 = params, currentPath = path, resolve = null render1 = (routeResolver.render || identity).bind(routeResolver) run1() } @@ -1107,9 +1107,15 @@ var _20 = function($window, redrawService0) { if (payload.view) update({}, payload, params, path) else { if (payload.onmatch) { - Promise.resolve(payload.onmatch(params, path)).then(function(resolved) { - update(payload, resolved, params, path) - }) + if (resolve != null) update(payload, component, params, path) + else { + resolve = function(resolved) { + update(payload, resolved, params, path) + } + Promise.resolve(payload.onmatch(params, path)).then(function(resolved) { + if (resolve != null) resolve(resolved) + }) + } } else update(payload, "div", params, path) } @@ -1118,7 +1124,10 @@ var _20 = function($window, redrawService0) { }) redrawService0.subscribe(root, run1) } - route.set = routeService.setPath + route.set = function(path, data, options) { + resolve = null + routeService.setPath(path, data, options) + } route.get = function() {return currentPath} route.prefix = routeService.setPrefix route.link = routeService.link diff --git a/mithril.min.js b/mithril.min.js index c0f2a5b2..cf44690d 100644 --- a/mithril.min.js +++ b/mithril.min.js @@ -1,41 +1,41 @@ -new function(){function m(a,c,h,d,g,l){return{tag:a,key:c,attrs:h,children:d,text:g,dom:l,domSize:void 0,state:{},events:void 0,instance:void 0,skip:!1}}function y(a){if(null==a||"string"!==typeof a&&null==a.view)throw Error("The selector must be either a string or a component.");if("string"===typeof a&&void 0===L[a]){for(var c,h,d=[],g={};c=Q.exec(a);){var l=c[1],t=c[2];""===l&&""!==t?h=t:"#"===l?g.id=t:"."===l?d.push(t):"["===c[3][0]&&((l=c[6])&&(l=l.replace(/\\(["'])/g,"$1").replace(/\\\\/g,"\\")), -"class"===c[4]?d.push(l):g[c[4]]=l||!0)}0a.indexOf("?")?"?":"&";a+=d+b}return a}function t(a){try{return""!==a?JSON.parse(a):null}catch(D){throw Error(a);}}function n(a){return a.responseText}function p(a, -c){if("function"===typeof a)if(c instanceof Array)for(var b=0;bk.status||304===k.status)c(p(b.type,a));else{var g=Error(k.responseText),h;for(h in a)g[h]=a[h];d(g)}}catch(F){d(F)}};h&&null!=b.data?k.send(b.data):k.send()});return!0===b.background?k:u(k)},jsonp:function(b,x){var t=h();b=d(b,x);var k=new c(function(c, -d){var k=b.callbackName||"_mithril_"+Math.round(1E16*Math.random())+"_"+m++,h=a.document.createElement("script");a[k]=function(d){h.parentNode.removeChild(h);c(p(b.type,d));delete a[k]};h.onerror=function(){h.parentNode.removeChild(h);d(Error("JSONP request failed"));delete a[k]};null==b.data&&(b.data={});b.url=g(b.url,b.data);b.data[b.callbackKey||"callback"]=k;h.src=l(b.url,b.data);a.document.documentElement.appendChild(h)});return!0===b.background?k:t(k)},setCompletionCallback:function(a){x=a}}}(window, -I),P=function(a){function c(e,f,a,b,c,d,g){for(;a=k&&u>=z;){var v=f[k],m=a[z];if(v!==m||r)if(null==v)k++;else if(null==m)z++;else if(v.key===m.key)k++,z++,l(e,v,m,b,n(f,k,d),r,g),r&&v.tag===m.tag&&p(e,t(v),d);else if(v=f[w],v!==m||r)if(null==v)w--;else if(null==m)z++;else if(v.key===m.key)l(e,v,m,b,n(f,w+1,d),r,g),(r||z=k&&u>=z;){v=f[w];m=a[u];if(v!==m||r)if(null==v)w--;else{if(null!= -m)if(v.key===m.key)l(e,v,m,b,n(f,w+1,d),r,g),r&&v.tag===m.tag&&p(e,t(v),d),null!=v.dom&&(d=v.dom),w--;else{if(!G){G=f;var v=w,B={},C;for(C=0;Ca.indexOf("?")?"?":"&";a+=d+b}return a}function n(a){try{return""!==a?JSON.parse(a):null}catch(F){throw Error(a);}}function A(a){return a.responseText}function m(a, +c){if("function"===typeof a)if(c instanceof Array)for(var b=0;bh.status||304===h.status)c(m(b.type,a));else{var g=Error(h.responseText),k;for(k in a)g[k]=a[k];d(g)}}catch(G){d(G)}};k&&null!=b.data?h.send(b.data):h.send()});return!0===b.background?t:u(t)},jsonp:function(b,h){var n=k();b=d(b,h);var t=new c(function(c, +d){var h=b.callbackName||"_mithril_"+Math.round(1E16*Math.random())+"_"+r++,k=a.document.createElement("script");a[h]=function(d){k.parentNode.removeChild(k);c(m(b.type,d));delete a[h]};k.onerror=function(){k.parentNode.removeChild(k);d(Error("JSONP request failed"));delete a[h]};null==b.data&&(b.data={});b.url=g(b.url,b.data);b.data[b.callbackKey||"callback"]=h;k.src=l(b.url,b.data);a.document.documentElement.appendChild(k)});return!0===b.background?t:n(t)},setCompletionCallback:function(a){h=a}}}(window, +J),Q=function(a){function c(e,f,a,b,c,d,h){for(;a=v&&u>=t;){var x=f[v],p=a[t];if(x!==p||q)if(null==x)v++;else if(null==p)t++;else if(x.key===p.key)v++,t++,l(e,x,p,b,A(f,v,d),q,g),q&&x.tag===p.tag&&m(e,n(x),d);else if(x=f[z],x!==p||q)if(null==x)z--;else if(null==p)t++;else if(x.key===p.key)l(e,x,p,b,A(f,z+1,d),q,g),(q||t=v&&u>=t;){x=f[z];p=a[u];if(x!==p||q)if(null==x)z--;else{if(null!= +p)if(x.key===p.key)l(e,x,p,b,A(f,z+1,d),q,g),q&&x.tag===p.tag&&m(e,n(x),d),null!=x.dom&&(d=x.dom),z--;else{if(!E){E=f;var x=z,r={},C;for(C=0;C