From cf12c00fa1445efbb033c88c5d89090a059b7608 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Gerardy Date: Tue, 6 Dec 2016 21:34:24 +0100 Subject: [PATCH 1/3] [router] don't mutate RouteResolvers, move a branch out of redraw --- api/router.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/api/router.js b/api/router.js index 1eace6b0..d1452782 100644 --- a/api/router.js +++ b/api/router.js @@ -8,16 +8,16 @@ module.exports = function($window, redrawService) { var routeService = coreRouter($window) var identity = function(v) {return v} - var resolver, component, attrs, currentPath, resolve + var render, component, attrs, 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) { - resolver = routeResolver, component = comp, attrs = params, currentPath = path, resolve = null - resolver.render = routeResolver.render || identity - render() + component = comp || "div", attrs = params, currentPath = path, resolve = null + render = (routeResolver.render || identity).bind(routeResolver) + run() } - var render = function() { - if (resolver != null) redrawService.render(root, resolver.render(Vnode(component || "div", attrs.key, attrs))) + var run = function() { + if (render != null) redrawService.render(root, render(Vnode(component, attrs.key, attrs))) } routeService.defineRoutes(routes, function(payload, params, path) { if (payload.view) update({}, payload, params, path) @@ -38,7 +38,7 @@ module.exports = function($window, redrawService) { }, function() { routeService.setPath(defaultRoute) }) - redrawService.subscribe(root, render) + redrawService.subscribe(root, run) } route.set = routeService.setPath route.get = function() {return currentPath} From 650f7c4f3b7dce3e32b5e6795c066d090026eb7a Mon Sep 17 00:00:00 2001 From: Pierre-Yves Gerardy Date: Tue, 6 Dec 2016 21:44:49 +0100 Subject: [PATCH 2/3] [router] remove logic made redundant by promise use --- api/router.js | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/api/router.js b/api/router.js index d1452782..04b5d091 100644 --- a/api/router.js +++ b/api/router.js @@ -8,11 +8,11 @@ module.exports = function($window, redrawService) { var routeService = coreRouter($window) var identity = function(v) {return v} - var render, component, attrs, currentPath, resolve + var render, component, attrs, currentPath 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", attrs = params, currentPath = path, resolve = null + component = comp || "div", attrs = params, currentPath = path render = (routeResolver.render || identity).bind(routeResolver) run() } @@ -23,15 +23,9 @@ module.exports = function($window, redrawService) { 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) - }) - } + Promise.resolve(payload.onmatch(params, path)).then(function(resolved) { + update(payload, resolved, params, path) + }) } else update(payload, "div", params, path) } From e73f4ba126e30030ab17554142203f82e76eaabf Mon Sep 17 00:00:00 2001 From: Gandalf-the-Bot Date: Tue, 6 Dec 2016 21:28:09 +0000 Subject: [PATCH 3/3] Bundled output for commit 678a8b13ae80c87c04f9dd416ade7b8011981fd3 [skip ci] --- README.md | 2 +- mithril.js | 26 ++++++---------- mithril.min.js | 82 +++++++++++++++++++++++++------------------------- 3 files changed, 52 insertions(+), 58 deletions(-) diff --git a/README.md b/README.md index ef729c3b..9ddad4bf 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.44 KB min+gzip +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 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 9baf3a09..64a76fb6 100644 --- a/mithril.js +++ b/mithril.js @@ -1092,37 +1092,31 @@ var coreRouter = function($window) { var _20 = function($window, redrawService0) { var routeService = coreRouter($window) var identity = function(v) {return v} - var resolver, component, attrs3, currentPath, resolve + var render1, component, attrs3, currentPath 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) { - resolver = routeResolver, component = comp, attrs3 = params, currentPath = path, resolve = null - resolver.render = routeResolver.render || identity - render1() + component = comp || "div", attrs3 = params, currentPath = path + render1 = (routeResolver.render || identity).bind(routeResolver) + run1() } - var render1 = function() { - if (resolver != null) redrawService0.render(root, resolver.render(Vnode(component || "div", attrs3.key, attrs3))) + var run1 = function() { + if (render1 != null) redrawService0.render(root, render1(Vnode(component, attrs3.key, attrs3))) } routeService.defineRoutes(routes, function(payload, params, path) { 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) - }) - } + Promise.resolve(payload.onmatch(params, path)).then(function(resolved) { + update(payload, resolved, params, path) + }) } else update(payload, "div", params, path) } }, function() { routeService.setPath(defaultRoute) }) - redrawService0.subscribe(root, render1) + redrawService0.subscribe(root, run1) } route.set = routeService.setPath route.get = function() {return currentPath} diff --git a/mithril.min.js b/mithril.min.js index 65d7de53..c0f2a5b2 100644 --- a/mithril.min.js +++ b/mithril.min.js @@ -1,41 +1,41 @@ -new function(){function r(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===K[a]){for(var c,h,d=[],g={};c=R.exec(a);){var l=c[1],m=c[2];""===l&&""!==m?h=m:"#"===l?g.id=m:"."===l?d.push(m):"["===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 m(a){try{return""!==a?JSON.parse(a):null}catch(O){throw Error(a);}}function A(a){return a.responseText}function n(a, -c){if("function"===typeof a)if(c instanceof Array)for(var b=0;bk.status||304===k.status)c(n(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?u:v(u)},jsonp:function(b,k){var m=h();b=d(b,k);var u=new c(function(c, -d){var k=b.callbackName||"_mithril_"+Math.round(1E16*Math.random())+"_"+r++,h=a.document.createElement("script");a[k]=function(d){h.parentNode.removeChild(h);c(n(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?u:m(u)},setCompletionCallback:function(a){k=a}}}(window, -H),Q=function(a){function c(e,f,a,b,c,d,g){for(;a=w&&v>=u;){var x=f[w],p=a[u];if(x!==p||q)if(null==x)w++;else if(null==p)u++;else if(x.key===p.key)w++,u++,l(e,x,p,b,A(f,w,d),q,g),q&&x.tag===p.tag&&n(e,m(x),d);else if(x=f[z],x!==p||q)if(null==x)z--;else if(null==p)u++;else if(x.key===p.key)l(e,x,p,b,A(f,z+1,d),q,g),(q||u=w&&v>=u;){x=f[z];p=a[v];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&&n(e,m(x),d),null!=x.dom&&(d=x.dom),z--;else{if(!D){D=f;var x=z,r={},C;for(C=0;Ca.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;C