From fbdf798e7956944d371a62986afbcea9bc23bda9 Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Fri, 2 Dec 2016 20:44:43 -0500 Subject: [PATCH] build --- README.md | 2 +- mithril.js | 63 +++++++++++++++++++++++---------------- mithril.min.js | 81 +++++++++++++++++++++++++------------------------- 3 files changed, 80 insertions(+), 66 deletions(-) diff --git a/README.md b/README.md index e1be8c2b..0256ede0 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.42 KB min+gzip +Despite the huge improvements in performance and modularity, the new codebase is smaller than v0.2.x, currently clocking at 7.45 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 46f2ae23..5a39e5fc 100644 --- a/mithril.js +++ b/mithril.js @@ -202,31 +202,34 @@ var buildQueryString = function(object) { } var _8 = function($window, Promise) { var callbackCount = 0 - var count = 0 var oncompletion function setCompletionCallback(callback) {oncompletion = callback} - function complete() {if (--count === 0 && typeof oncompletion === "function") oncompletion()} - function finalize(promise0) { - var then0 = promise0.then - promise0.then = function() { - count++ - var next = then0.apply(promise0, arguments) - next.then(complete, function(e) { - complete() - throw e - }) - return finalize(next) + function finalizer() { + var count = 0 + function complete() {if (--count === 0 && typeof oncompletion === "function") oncompletion()} + return function finalize(promise0) { + var then0 = promise0.then, catcher = promise0.catch + promise0.then = function() { + count++ + var next = then0.apply(promise0, arguments) + next.then(complete, function(e) { + complete() + throw e + }) + return finalize(next) + } + return promise0 } - return promise0 } function request(args, extra) { - return finalize(new Promise(function(resolve, reject) { - if (typeof args === "string") { - var url = args - args = extra || {} - if (args.url == null) args.url = url - } + var finalize = finalizer() + if (typeof args === "string") { + var url = args + args = extra || {} + if (args.url == null) args.url = url + } + var promise0 = new Promise(function(resolve, reject) { if (args.method == null) args.method = "GET" args.method = args.method.toUpperCase() var useBody = typeof args.useBody === "boolean" ? args.useBody : args.method !== "GET" && args.method !== "TRACE" @@ -266,10 +269,12 @@ var _8 = function($window, Promise) { } if (useBody && (args.data != null)) xhr.send(args.data) else xhr.send() - })) + }) + return args.redraw === false ? promise0 : finalize(promise0) } function jsonp(args) { - return finalize(new Promise(function(resolve, reject) { + var finalize = finalizer() + var promise0 = new Promise(function(resolve, reject) { var callbackName = args.callbackName || "_mithril_" + Math.round(Math.random() * 1e16) + "_" + callbackCount++ var script = $window.document.createElement("script") $window[callbackName] = function(data) { @@ -287,7 +292,8 @@ var _8 = function($window, Promise) { args.data[args.callbackKey || "callback"] = callbackName script.src = assemble(args.url, args.data) $window.document.documentElement.appendChild(script) - })) + }) + return args.redraw === false? promise0 : finalize(promise0) } function interpolate(url, data) { if (data == null) return url @@ -441,9 +447,16 @@ var coreRenderer = function($window) { else if (old == null) createNodes(parent, vnodes, 0, vnodes.length, hooks, nextSibling, undefined) else if (vnodes == null) removeNodes(old, 0, old.length, vnodes) else { - if (old.length === vnodes.length && vnodes[0] != null && vnodes[0].key == null) { + var isUnkeyed = false + for (var i = 0; i < vnodes.length; i++) { + if (vnodes[i] != null) { + isUnkeyed = vnodes[i].key == null + break + } + } + if (old.length === vnodes.length && isUnkeyed) { for (var i = 0; i < old.length; i++) { - if (old[i] === vnodes[i] || old[i] == null && vnodes[i] == null) continue + if (old[i] === vnodes[i]) continue else if (old[i] == null) insertNode(parent, createNode(vnodes[i], hooks, ns), getNextSibling(old, i + 1, nextSibling)) else if (vnodes[i] == null) removeNodes(old, i, i + 1, vnodes) else updateNode(parent, old[i], vnodes[i], hooks, getNextSibling(old, i + 1, nextSibling), false, ns) @@ -1124,7 +1137,7 @@ m.request = requestService.request m.jsonp = requestService.jsonp m.parseQueryString = parseQueryString m.buildQueryString = buildQueryString -m.version = "1.0.0-rc.5" +m.version = "1.0.0-rc.6" if (typeof module !== "undefined") module["exports"] = m else window.m = m } \ No newline at end of file diff --git a/mithril.min.js b/mithril.min.js index 7935777e..9af6482c 100644 --- a/mithril.min.js +++ b/mithril.min.js @@ -1,40 +1,41 @@ -new function(){function n(a,h,l,b,f,k){return{tag:a,key:h,attrs:l,children:b,text:f,dom:k,domSize:void 0,state:{},events:void 0,instance:void 0,skip:!1}}function A(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===I[a]){for(var h,l,b=[],f={};h=O.exec(a);){var k=h[1],v=h[2];""===k&&""!==v?l=v:"#"===k?f.id=v:"."===k?b.push(v):"["===h[3][0]&&((k=h[6])&&(k=k.replace(/\\(["'])/g,"$1").replace(/\\\\/g,"\\")), -"class"===h[4]?b.push(k):f[h[4]]=k||!0)}0a.indexOf("?")?"?":"&";a+=f+d}return a}function v(a){try{return""!== -a?JSON.parse(a):null}catch(w){throw Error(a);}}function p(a){return a.responseText}function q(a,b){if("function"===typeof a)if(b instanceof Array)for(var d=0;dm.status||304===m.status)b(q(d.type,a));else{var f=Error(m.responseText),k;for(k in a)f[k]=a[k];h(f)}}catch(G){h(G)}}; -r&&null!=d.data?m.send(d.data):m.send()}))},jsonp:function(d){return b(new h(function(b,h){var m=d.callbackName||"_mithril_"+Math.round(1E16*Math.random())+"_"+n++,r=a.document.createElement("script");a[m]=function(f){r.parentNode.removeChild(r);b(q(d.type,f));delete a[m]};r.onerror=function(){r.parentNode.removeChild(r);h(Error("JSONP request failed"));delete a[m]};null==d.data&&(d.data={});d.url=f(d.url,d.data);d.data[d.callbackKey||"callback"]=m;r.src=k(d.url,d.data);a.document.documentElement.appendChild(r)}))}, -setCompletionCallback:function(a){m=a}}}(window,"undefined"!==typeof Promise?Promise:t),N=function(a){function h(g,c,a,b,d,f,h){for(;a=m&&u>=y;){var x=c[m],n=a[y];if(x!==n||e)if(null==x)m++;else if(null==n)y++;else if(x.key===n.key)m++,y++,k(g,x,n,d,p(c,m,b),e,f),e&&x.tag===n.tag&&q(g,v(x),b);else if(x=c[z],x!==n||e)if(null==x)z--;else if(null==n)y++;else if(x.key===n.key)k(g,x,n,d,p(c,z+1,b),e,f),(e||y= -m&&u>=y;){x=c[z];n=a[u];if(x!==n||e)if(null==x)z--;else{if(null!=n)if(x.key===n.key)k(g,x,n,d,p(c,z+1,b),e,f),e&&x.tag===n.tag&&q(g,v(x),b),null!=x.dom&&(b=x.dom),z--;else{if(!w){w=c;var x=z,D={},t;for(t=0;tb.indexOf("?")?"?":"&";b+=d+c}return b} +function h(b){try{return""!==b?JSON.parse(b):null}catch(k){throw Error(b);}}function q(b){return b.responseText}function n(b,a){if("function"===typeof b)if(a instanceof Array)for(var c=0;cm.status||304===m.status)f(n(b.type,a));else{var c=Error(m.responseText), +d;for(d in a)c[d]=a[d];k(c)}}catch(G){k(G)}};g&&null!=b.data?m.send(b.data):m.send()});return!1===b.redraw?t:m(t)},jsonp:function(b){var k=g(),h=new f(function(f,h){var k=b.callbackName||"_mithril_"+Math.round(1E16*Math.random())+"_"+m++,g=a.document.createElement("script");a[k]=function(c){g.parentNode.removeChild(g);f(n(b.type,c));delete a[k]};g.onerror=function(){g.parentNode.removeChild(g);h(Error("JSONP request failed"));delete a[k]};null==b.data&&(b.data={});b.url=c(b.url,b.data);b.data[b.callbackKey|| +"callback"]=k;g.src=d(b.url,b.data);a.document.documentElement.appendChild(g)});return!1===b.redraw?h:k(h)},setCompletionCallback:function(a){r=a}}}(window,"undefined"!==typeof Promise?Promise:x),N=function(a){function f(e,l,a,b,c,d,f){for(;a=u&&y>=z;){var w=l[u],r=a[z];if(w!==r||p)if(null==w)u++;else if(null==r)z++;else if(w.key===r.key)u++,z++,h(e,w,r,c,n(l,u,d),p,k),p&&w.tag===r.tag&&m(e,q(w),d);else if(w=l[t],w!==r||p)if(null==w)t--;else if(null==r)z++;else if(w.key=== +r.key)h(e,w,r,c,n(l,t+1,d),p,k),(p||z=u&&y>=z;){w=l[t];r=a[y];if(w!==r||p)if(null==w)t--;else{if(null!=r)if(w.key===r.key)h(e,w,r,c,n(l,t+1,d),p,k),p&&w.tag===r.tag&&m(e,q(w),d),null!=w.dom&&(d=w.dom),t--;else{if(!E){E=l;var w=t,v={},C;for(C=0;C