From 29ee36e9675707fea058a68c4f05bc01cc4dd2ce Mon Sep 17 00:00:00 2001 From: Gandalf-the-Bot Date: Thu, 18 Aug 2016 03:55:23 +0000 Subject: [PATCH] Bundled output for commit 3761226c2c911e04026b876fdd2132e055dc1d61 [skip ci] --- mithril.js | 66 ++++++++++++++++++++++------------------ mithril.min.js | 82 +++++++++++++++++++++++++------------------------- 2 files changed, 78 insertions(+), 70 deletions(-) diff --git a/mithril.js b/mithril.js index bf4d6b8e..4974e591 100644 --- a/mithril.js +++ b/mithril.js @@ -264,7 +264,7 @@ var renderService = function($window) { else updateComponent(parent, old, vnode, hooks, nextSibling, recycling, ns) } else { - removeNode(parent, old, null, false) + removeNode(parent, old, null) insertNode(parent, createNode(vnode, hooks, undefined), nextSibling) } } @@ -326,7 +326,7 @@ var renderService = function($window) { vnode.domSize = vnode.instance.domSize } else if (old.instance != null) { - removeNode(parent, old.instance, null, false) + removeNode(parent, old.instance, null) vnode.dom = undefined vnode.domSize = 0 } @@ -386,40 +386,48 @@ var renderService = function($window) { var vnode = vnodes[i] if (vnode != null) { if (vnode.skip) vnode.skip = false - else removeNode(parent, vnode, context, false) + else removeNode(parent, vnode, context) } } } - function removeNode(parent, vnode, context, deferred) { - if (deferred === false) { - var expected = 0, called = 0 - var callback = function() { - if (++called === expected) removeNode(parent, vnode, context, true) + function once(f) { + var called = false + return function() { + if (!called) { + called = true + f() } - if (vnode.attrs && vnode.attrs.onbeforeremove) { - expected++ - vnode.attrs.onbeforeremove.call(vnode.state, vnode, callback) - } - if (typeof vnode.tag !== "string" && vnode.tag.onbeforeremove) { - expected++ - vnode.tag.onbeforeremove.call(vnode.state, vnode, callback) - } - if (expected > 0) return } - onremove(vnode) - if (vnode.dom) { - var count = vnode.domSize || 1 - if (count > 1) { - var dom = vnode.dom - while (--count) { - parent.removeChild(dom.nextSibling) + } + function removeNode(parent, vnode, context) { + var expected = 1, called = 0 + if (vnode.attrs && vnode.attrs.onbeforeremove) { + expected++ + vnode.attrs.onbeforeremove.call(vnode.state, vnode, once(continuation)) + } + if (typeof vnode.tag !== "string" && vnode.tag.onbeforeremove) { + expected++ + vnode.tag.onbeforeremove.call(vnode.state, vnode, once(continuation)) + } + continuation() + function continuation() { + if (++called === expected) { + onremove(vnode) + if (vnode.dom) { + var count = vnode.domSize || 1 + if (count > 1) { + var dom = vnode.dom + while (--count) { + parent.removeChild(dom.nextSibling) + } + } + if (vnode.dom.parentNode != null) parent.removeChild(vnode.dom) + if (context != null && vnode.domSize == null && !hasIntegrationMethods(vnode.attrs) && typeof vnode.tag === "string") { //TODO test custom elements + if (!context.pool) context.pool = [vnode] + else context.pool.push(vnode) + } } } - if (vnode.dom.parentNode != null) parent.removeChild(vnode.dom) - if (context != null && vnode.domSize == null && !hasIntegrationMethods(vnode.attrs) && typeof vnode.tag === "string") { //TODO test custom elements - if (!context.pool) context.pool = [vnode] - else context.pool.push(vnode) - } } } function onremove(vnode) { diff --git a/mithril.min.js b/mithril.min.js index cfc9f7d8..108951f9 100644 --- a/mithril.min.js +++ b/mithril.min.js @@ -1,41 +1,41 @@ -new function(){function w(b,d,p,g,k,n){return{tag:b,key:d,attrs:p,children:g,text:k,dom:n,domSize:void 0,state:{},events:void 0,instance:void 0,skip:!1}}w.normalize=function(b){return b instanceof Array?w("[",void 0,void 0,w.normalizeChildren(b),void 0,void 0):null!=b&&"object"!==typeof b?w("#",void 0,void 0,b,void 0,void 0):b};w.normalizeChildren=function(b){for(var d=0;d=q&&y>=B;){var h=a[q],v=e[B];if(h===v)q++,B++;else if(null!=h&&null!=v&&h.key===v.key)q++,B++,n(c,h,v,f,t(a,q,b),r,l),r&&h.tag===v.tag&&x(c,m(h),b);else if(h=a[g],h===v)g--,B++;else if(null!=h&&null!=v&&h.key===v.key)n(c,h,v,f,t(a,g+1,b),r,l),B=q&&y>=B;){h=a[g];v=e[y];if(h===v)g--;else if(null!=h&&null!=v&&h.key===v.key)n(c,h,v,f,t(a,g+1,b),r,l),r&&h.tag===v.tag&&x(c,m(h),b), -null!=h.dom&&(b=h.dom),g--;else{if(!k){k=a;var h=g,z={},w;for(w=0;wb.indexOf("?")?"?":"&";b+=g+h}return b}function k(b){try{return""!==b?JSON.parse(b):null}catch(d){throw Error(b);}}function n(b){return b.responseText}function m(b,d){if("function"===typeof b)if(d instanceof Array)for(var g=0;gl.status)d(m(f.type, -b));else{var g=Error(l.responseText),h;for(h in b)g[h]=b[h];d.error(g)}}catch(x){d.error(x)}"function"===typeof u&&u()}};h?l.send(f.data):l.send();return d},jsonp:function(d){var k=t();void 0!==d.initialValue&&k(d.initialValue);var h=d.callbackName||"_mithril_"+Math.round(1E16*Math.random())+"_"+x++,l=b.document.createElement("script");b[h]=function(g){l.parentNode.removeChild(l);k(m(d.type,g));"function"===typeof u&&u();delete b[h]};l.onerror=function(){l.parentNode.removeChild(l);k.error(Error("JSONP request failed")); -"function"===typeof u&&u();delete b[h]};null==d.data&&(d.data={});d.url=p(d.url,d.data);d.data[d.callbackKey||"callback"]=h;l.src=g(d.url,d.data);b.document.documentElement.appendChild(l);return k},setCompletionCallback:function(b){u=b}}}(window,console.error.bind(console)),D=function(){var b=[];return{subscribe:b.push.bind(b),unsubscribe:function(d){d=b.indexOf(d);-1=t&&A>=B;){var h=a[t],v=f[B];if(h===v)t++,B++;else if(null!=h&&null!=v&&h.key===v.key)t++,B++,k(c,h,v,e,l(a,t,b),q,p),q&&h.tag===v.tag&&w(c,m(h),b);else if(h=a[g],h===v)g--,B++;else if(null!=h&&null!=v&&h.key===v.key)k(c,h,v,e,l(a,g+1,b),q,p),B=t&&A>=B;){h=a[g];v=f[A];if(h===v)g--;else if(null!=h&&null!=v&&h.key===v.key)k(c,h,v,e,l(a,g+1,b),q,p),q&&h.tag===v.tag&&w(c,m(h),b), +null!=h.dom&&(b=h.dom),g--;else{if(!n){n=a;var h=g,x={},u;for(u=0;ub.indexOf("?")?"?":"&";b+=p+g}return b}function n(b){try{return""!==b?JSON.parse(b):null}catch(d){throw Error(b);}}function k(b){return b.responseText}function m(b,d){if("function"===typeof b)if(d instanceof Array)for(var g=0;gp.status)d(m(e.type, +b));else{var g=Error(p.responseText),h;for(h in b)g[h]=b[h];d.error(g)}}catch(w){d.error(w)}"function"===typeof y&&y()}};h?p.send(e.data):p.send();return d},jsonp:function(e){var d=l();void 0!==e.initialValue&&d(e.initialValue);var h=e.callbackName||"_mithril_"+Math.round(1E16*Math.random())+"_"+w++,p=b.document.createElement("script");b[h]=function(g){p.parentNode.removeChild(p);d(m(e.type,g));"function"===typeof y&&y();delete b[h]};p.onerror=function(){p.parentNode.removeChild(p);d.error(Error("JSONP request failed")); +"function"===typeof y&&y();delete b[h]};null==e.data&&(e.data={});e.url=r(e.url,e.data);e.data[e.callbackKey||"callback"]=h;p.src=g(e.url,e.data);b.document.documentElement.appendChild(p);return d},setCompletionCallback:function(b){y=b}}}(window,console.error.bind(console)),D=function(){var b=[];return{subscribe:b.push.bind(b),unsubscribe:function(d){d=b.indexOf(d);-1