diff --git a/README.md b/README.md index 3b577d13..11a87ed7 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.50 KB min+gzip +Despite the huge improvements in performance and modularity, the new codebase is smaller than v0.2.x, currently clocking at 7.47 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 02b87bb3..e5558df4 100644 --- a/mithril.js +++ b/mithril.js @@ -1081,11 +1081,11 @@ var coreRouter = function($window) { var _20 = function($window, redrawService0) { var routeService = coreRouter($window) var identity = function(v) {return v} - var routing = false, render1, component, attrs3, currentPath, resolve + var render1, component, attrs3, currentPath, updatePending = false 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 != null && typeof comp.view === "function" ? comp : "div", attrs3 = params, currentPath = path, resolve = null + component = comp != null && typeof comp.view === "function" ? comp : "div", attrs3 = params, currentPath = path, updatePending = false render1 = (routeResolver.render || identity).bind(routeResolver) run1() } @@ -1099,15 +1099,10 @@ var _20 = function($window, redrawService0) { if (payload.view) update({}, payload, params, path) else { if (payload.onmatch) { - 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) - }, bail) - } + updatePending = true + Promise.resolve(payload.onmatch(params, path)).then(function(resolved) { + if (updatePending) update(payload, resolved, params, path) + }, bail) } else update(payload, "div", params, path) } @@ -1115,8 +1110,8 @@ var _20 = function($window, redrawService0) { redrawService0.subscribe(root, run1) } route.set = function(path, data, options) { - if (resolve != null) options = {replace: true} - resolve = null + if (updatePending) options = {replace: true} + updatePending = false routeService.setPath(path, data, options) } route.get = function() {return currentPath} diff --git a/mithril.min.js b/mithril.min.js index 801c1241..69e76332 100644 --- a/mithril.min.js +++ b/mithril.min.js @@ -1,41 +1,41 @@ -new function(){function y(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 B(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===K[a]){for(var c,h,d=[],g={};c=P.exec(a);){var l=c[1],k=c[2];""===l&&""!==k?h=k:"#"===l?g.id=k:"."===l?d.push(k):"["===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 k(a){try{return""!==a?JSON.parse(a):null}catch(r){throw Error(a);}}function n(a){return a.responseText}function m(a, -c){if("function"===typeof a)if(c instanceof Array)for(var b=0;bz.status||304===z.status)c(m(b.type,a));else{var g=Error(z.responseText),h;for(h in a)g[h]=a[h];d(g)}}catch(F){d(F)}};h&&null!=b.data?z.send(b.data):z.send()});return!0===b.background?w:t(w)},jsonp:function(b,k){var n=h();b=d(b,k);var w=new c(function(c, -d){var h=b.callbackName||"_mithril_"+Math.round(1E16*Math.random())+"_"+p++,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?w:n(w)},setCompletionCallback:function(a){t=a}}}(window, -H),O=function(a){function c(e,f,a,b,c,d,g){for(;a=u&&w>=A;){var r=f[u],v=a[A];if(r!==v||q)if(null==r)u++;else if(null==v)A++;else if(r.key===v.key)u++,A++,l(e,r,v,b,n(f,u,d),q,g),q&&r.tag===v.tag&&m(e,k(r),d);else if(r=f[p],r!==v||q)if(null==r)p--;else if(null==v)A++;else if(r.key===v.key)l(e,r,v,b,n(f,p+1,d),q,g),(q||A=u&&w>=A;){r=f[p];v=a[w];if(r!==v||q)if(null==r)p--;else{if(null!= -v)if(r.key===v.key)l(e,r,v,b,n(f,p+1,d),q,g),q&&r.tag===v.tag&&m(e,k(r),d),null!=r.dom&&(d=r.dom),p--;else{if(!z){z=f;var r=p,D={},y;for(y=0;ya.indexOf("?")?"?":"&";a+=d+b}return a}function l(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?t:r(t)},jsonp:function(b,l){var n=h();b=d(b,l);var t=new c(function(c, +d){var h=b.callbackName||"_mithril_"+Math.round(1E16*Math.random())+"_"+k++,l=a.document.createElement("script");a[h]=function(d){l.parentNode.removeChild(l);c(p(b.type,d));delete a[h]};l.onerror=function(){l.parentNode.removeChild(l);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;l.src=m(b.url,b.data);a.document.documentElement.appendChild(l)});return!0===b.background?t:n(t)},setCompletionCallback:function(a){r=a}}}(window, +H),O=function(a){function c(e,f,a,b,c,d,g){for(;a=k&&t>=A;){var x=f[k],u=a[A];if(x!==u||q)if(null==x)k++;else if(null==u)A++;else if(x.key===u.key)k++,A++,m(e,x,u,b,n(f,k,d),q,g),q&&x.tag===u.tag&&p(e,l(x),d);else if(x=f[y],x!==u||q)if(null==x)y--;else if(null==u)A++;else if(x.key===u.key)m(e,x,u,b,n(f,y+1,d),q,g),(q||A=k&&t>=A;){x=f[y];u=a[t];if(x!==u||q)if(null==x)y--;else{if(null!= +u)if(x.key===u.key)m(e,x,u,b,n(f,y+1,d),q,g),q&&x.tag===u.tag&&p(e,l(x),d),null!=x.dom&&(d=x.dom),y--;else{if(!D){D=f;var x=y,C={},w;for(w=0;w