fix update lifecycle in children of recycled

This commit is contained in:
Leo 2017-02-10 10:09:18 -05:00
parent 0d9a51fe37
commit 632677e00c
5 changed files with 110 additions and 50 deletions

View file

@ -1,11 +1,21 @@
# Change log
- [v1.0.2](#v101)
- [v1.0.1](#v101)
- [Migrating from v0.2.x](#migrating-from-v02x)
- [Older docs](http://mithril.js.org/archive/v0.2.5/index.html)
---
### v1.0.2
#### Bug fixes
- fix IE11 input[type] error - [#1610](https://github.com/lhorie/mithril.js/issues/1610)
- apply [#1609](https://github.com/lhorie/mithril.js/issues/1609) to unkeyed children case
---
### v1.0.1
#### News

View file

@ -481,7 +481,10 @@ var coreRenderer = function($window) {
}
}
recycling = recycling || isRecyclable(old, vnodes)
if (recycling) old = old.concat(old.pool)
if (recycling) {
var pool = old.pool
old = old.concat(old.pool)
}
var oldStart = 0, start = 0, oldEnd = old.length - 1, end = vnodes.length - 1, map
while (oldEnd >= oldStart && end >= start) {
var o = old[oldStart], v = vnodes[start]
@ -489,8 +492,9 @@ var coreRenderer = function($window) {
else if (o == null) oldStart++
else if (v == null) start++
else if (o.key === v.key) {
var shouldRecycle = (pool != null && oldStart >= old.length - pool.length) || ((pool == null) && recycling)
oldStart++, start++
updateNode(parent, o, v, hooks, getNextSibling(old, oldStart, nextSibling), recycling, ns)
updateNode(parent, o, v, hooks, getNextSibling(old, oldStart, nextSibling), shouldRecycle, ns)
if (recycling && o.tag === v.tag) insertNode(parent, toFragment(o), nextSibling)
}
else {
@ -499,7 +503,8 @@ var coreRenderer = function($window) {
else if (o == null) oldEnd--
else if (v == null) start++
else if (o.key === v.key) {
updateNode(parent, o, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), recycling, ns)
var shouldRecycle = (pool != null && oldEnd >= old.length - pool.length) || ((pool == null) && recycling)
updateNode(parent, o, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), shouldRecycle, ns)
if (recycling || start < end) insertNode(parent, toFragment(o), getNextSibling(old, oldStart, nextSibling))
oldEnd--, start++
}
@ -512,7 +517,8 @@ var coreRenderer = function($window) {
else if (o == null) oldEnd--
else if (v == null) end--
else if (o.key === v.key) {
updateNode(parent, o, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), recycling, ns)
var shouldRecycle = (pool != null && oldEnd >= old.length - pool.length) || ((pool == null) && recycling)
updateNode(parent, o, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), shouldRecycle, ns)
if (recycling && o.tag === v.tag) insertNode(parent, toFragment(o), nextSibling)
if (o.dom != null) nextSibling = o.dom
oldEnd--, end--
@ -523,6 +529,7 @@ var coreRenderer = function($window) {
var oldIndex = map[v.key]
if (oldIndex != null) {
var movable = old[oldIndex]
var shouldRecycle = (pool != null && oldIndex >= old.length - pool.length) || ((pool == null) && recycling)
updateNode(parent, movable, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), recycling, ns)
insertNode(parent, toFragment(movable), nextSibling)
old[oldIndex].skip = true

84
mithril.min.js vendored
View file

@ -1,42 +1,42 @@
new function(){function w(a,d,h,f,g,l){return{tag:a,key:d,attrs:h,children:f,text:g,dom:l,domSize:void 0,state:{},events:void 0,instance:void 0,skip:!1}}function z(a){if(null==a||"string"!==typeof a&&"function"!==typeof a.view)throw Error("The selector must be either a string or a component.");if("string"===typeof a&&void 0===G[a]){for(var d,h,f=[],g={};d=N.exec(a);){var l=d[1],k=d[2];""===l&&""!==k?h=k:"#"===l?g.id=k:"."===l?f.push(k):"["===d[3][0]&&((l=d[6])&&(l=l.replace(/\\(["'])/g,"$1").replace(/\\\\/g,
"\\")),"class"===d[4]?f.push(l):g[d[4]]=l||!0)}0<f.length&&(g.className=f.join(" "));G[a]=function(a,d){var l=!1,b,f,p=a.className||a["class"],m;for(m in g)a[m]=g[m];void 0!==p&&(void 0!==a["class"]&&(a["class"]=void 0,a.className=p),void 0!==g.className&&(a.className=g.className+" "+p));for(m in a)if("key"!==m){l=!0;break}Array.isArray(d)&&1==d.length&&null!=d[0]&&"#"===d[0].tag?f=d[0].children:b=d;return w(h||"div",a.key,l?a:void 0,b,f,void 0)}}var m;null==arguments[1]||"object"===typeof arguments[1]&&
void 0===arguments[1].tag&&!Array.isArray(arguments[1])?(m=arguments[1],f=2):f=1;if(arguments.length===f+1)d=Array.isArray(arguments[f])?arguments[f]:[arguments[f]];else for(d=[];f<arguments.length;f++)d.push(arguments[f]);return"string"===typeof a?G[a](m||{},w.normalizeChildren(d)):w(a,m&&m.key,m||{},w.normalizeChildren(d),void 0,void 0)}function O(a){var d=0,h=null,f="function"===typeof requestAnimationFrame?requestAnimationFrame:setTimeout;return function(){var g=Date.now();0===d||16<=g-d?(d=g,
a()):null===h&&(h=f(function(){h=null;a();d=Date.now()},16-(g-d)))}}w.normalize=function(a){return Array.isArray(a)?w("[",void 0,void 0,w.normalizeChildren(a),void 0,void 0):null!=a&&"object"!==typeof a?w("#",void 0,void 0,!1===a?"":a,void 0,void 0):a};w.normalizeChildren=function(a){for(var d=0;d<a.length;d++)a[d]=w.normalize(a[d]);return a};var N=/(?:(^|#|\.)([^#\.\[\]]+))|(\[(.+?)(?:\s*=\s*("|'|)((?:\\["'\]]|.)*?)\5)?\])/g,G={};z.trust=function(a){null==a&&(a="");return w("<",void 0,void 0,a,void 0,
void 0)};z.fragment=function(a,d){return w("[",a.key,a,w.normalizeChildren(d),void 0,void 0)};var v=function(a){function d(a,b){return function y(d){var k;try{if(!b||null==d||"object"!==typeof d&&"function"!==typeof d||"function"!==typeof(k=d.then))u(function(){b||0!==a.length||console.error("Possible unhandled promise rejection:",d);for(var f=0;f<a.length;f++)a[f](d);g.length=0;l.length=0;p.state=b;p.retry=function(){y(d)}});else{if(d===f)throw new TypeError("Promise can't be resolved w/ itself");
h(k.bind(d))}}catch(P){m(P)}}}function h(a){function b(b){return function(a){0<d++||b(a)}}var d=0,f=b(m);try{a(b(k),f)}catch(D){f(D)}}if(!(this instanceof v))throw Error("Promise must be called with `new`");if("function"!==typeof a)throw new TypeError("executor must be a function");var f=this,g=[],l=[],k=d(g,!0),m=d(l,!1),p=f._instance={resolvers:g,rejectors:l},u="function"===typeof setImmediate?setImmediate:setTimeout;h(a)};v.prototype.then=function(a,d){function h(a,d,h,k){d.push(function(b){if("function"!==
typeof a)h(b);else try{g(a(b))}catch(B){l&&l(B)}});"function"===typeof f.retry&&k===f.state&&f.retry()}var f=this._instance,g,l,k=new v(function(a,d){g=a;l=d});h(a,f.resolvers,g,!0);h(d,f.rejectors,l,!1);return k};v.prototype["catch"]=function(a){return this.then(null,a)};v.resolve=function(a){return a instanceof v?a:new v(function(d){d(a)})};v.reject=function(a){return new v(function(d,h){h(a)})};v.all=function(a){return new v(function(d,h){var f=a.length,g=0,l=[];if(0===a.length)d([]);else for(var k=
0;k<a.length;k++)(function(k){function p(a){g++;l[k]=a;g===f&&d(l)}null==a[k]||"object"!==typeof a[k]&&"function"!==typeof a[k]||"function"!==typeof a[k].then?p(a[k]):a[k].then(p,h)})(k)})};v.race=function(a){return new v(function(d,h){for(var f=0;f<a.length;f++)a[f].then(d,h)})};"undefined"!==typeof window?("undefined"===typeof window.Promise&&(window.Promise=v),v=window.Promise):"undefined"!==typeof global&&("undefined"===typeof global.Promise&&(global.Promise=v),v=global.Promise);var E=function(a){function d(a,
f){if(Array.isArray(f))for(var g=0;g<f.length;g++)d(a+"["+g+"]",f[g]);else if("[object Object]"===Object.prototype.toString.call(f))for(g in f)d(a+"["+g+"]",f[g]);else h.push(encodeURIComponent(a)+(null!=f&&""!==f?"="+encodeURIComponent(f):""))}if("[object Object]"!==Object.prototype.toString.call(a))return"";var h=[],f;for(f in a)d(f,a[f]);return h.join("&")},I=function(a,d){function h(){function b(){0===--a&&"function"===typeof x&&x()}var a=0;return function D(d){var f=d.then;d.then=function(){a++;
var g=f.apply(d,arguments);g.then(b,function(d){b();if(0===a)throw d;});return D(g)};return d}}function f(b,a){if("string"===typeof b){var d=b;b=a||{};null==b.url&&(b.url=d)}return b}function g(b,a){if(null==a)return b;for(var d=b.match(/:[^\/]+/gi)||[],f=0;f<d.length;f++){var g=d[f].slice(1);null!=a[g]&&(b=b.replace(d[f],a[g]))}return b}function l(b,a){var d=E(a);if(""!==d){var f=0>b.indexOf("?")?"?":"&";b+=f+d}return b}function k(b){try{return""!==b?JSON.parse(b):null}catch(B){throw Error(b);}}
function m(b){return b.responseText}function p(b,a){if("function"===typeof b)if(Array.isArray(a))for(var d=0;d<a.length;d++)a[d]=new b(a[d]);else return new b(a);return a}var u=0,x;return{request:function(b,x){var u=h();b=f(b,x);var B=new d(function(d,f){null==b.method&&(b.method="GET");b.method=b.method.toUpperCase();var h="boolean"===typeof b.useBody?b.useBody:"GET"!==b.method&&"TRACE"!==b.method;"function"!==typeof b.serialize&&(b.serialize="undefined"!==typeof FormData&&b.data instanceof FormData?
function(a){return a}:JSON.stringify);"function"!==typeof b.deserialize&&(b.deserialize=k);"function"!==typeof b.extract&&(b.extract=m);b.url=g(b.url,b.data);h?b.data=b.serialize(b.data):b.url=l(b.url,b.data);var q=new a.XMLHttpRequest;q.open(b.method,b.url,"boolean"===typeof b.async?b.async:!0,"string"===typeof b.user?b.user:void 0,"string"===typeof b.password?b.password:void 0);b.serialize===JSON.stringify&&h&&q.setRequestHeader("Content-Type","application/json; charset=utf-8");b.deserialize===
k&&q.setRequestHeader("Accept","application/json, text/*");b.withCredentials&&(q.withCredentials=b.withCredentials);for(var x in b.headers)({}).hasOwnProperty.call(b.headers,x)&&q.setRequestHeader(x,b.headers[x]);"function"===typeof b.config&&(q=b.config(q,b)||q);q.onreadystatechange=function(){if(q.status&&4===q.readyState)try{var a=b.extract!==m?b.extract(q,b):b.deserialize(b.extract(q,b));if(200<=q.status&&300>q.status||304===q.status)d(p(b.type,a));else{var n=Error(q.responseText),c;for(c in a)n[c]=
a[c];f(n)}}catch(e){f(e)}};h&&null!=b.data?q.send(b.data):q.send()});return!0===b.background?B:u(B)},jsonp:function(b,k){var m=h();b=f(b,k);var x=new d(function(d,f){var h=b.callbackName||"_mithril_"+Math.round(1E16*Math.random())+"_"+u++,k=a.document.createElement("script");a[h]=function(f){k.parentNode.removeChild(k);d(p(b.type,f));delete a[h]};k.onerror=function(){k.parentNode.removeChild(k);f(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?x:m(x)},setCompletionCallback:function(a){x=a}}}(window,v),M=function(a){function d(a,c,e,b,d,f,g){for(;e<b;e++){var n=c[e];null!=n&&h(a,n,d,g,f)}}function h(a,c,e,b,g){var n=c.tag;null!=c.attrs&&v(c.attrs,c,e);if("string"===typeof n)switch(n){case "#":return c.dom=q.createTextNode(c.children),p(a,c.dom,g),c.dom;case "<":return f(a,c,g);case "[":var r=q.createDocumentFragment();null!=c.children&&
(n=c.children,d(r,n,0,n.length,e,null,b));c.dom=r.firstChild;c.domSize=r.childNodes.length;p(a,r,g);return r;default:var k=c.tag;switch(c.tag){case "svg":b="http://www.w3.org/2000/svg";break;case "math":b="http://www.w3.org/1998/Math/MathML"}var l=(n=c.attrs)&&n.is,k=b?l?q.createElementNS(b,k,{is:l}):q.createElementNS(b,k):l?q.createElement(k,{is:l}):q.createElement(k);c.dom=k;if(null!=n)for(r in l=b,n)y(c,r,null,n[r],l);p(a,k,g);null!=c.attrs&&null!=c.attrs.contenteditable?u(c):(null!=c.text&&(""!==
c.text?k.textContent=c.text:c.children=[w("#",void 0,void 0,c.text,void 0,void 0)]),null!=c.children&&(a=c.children,d(k,a,0,a.length,e,null,b),a=c.attrs,"select"===c.tag&&null!=a&&("value"in a&&y(c,"value",null,a.value,void 0),"selectedIndex"in a&&y(c,"selectedIndex",null,a.selectedIndex,void 0))));return k}else{c.state=Object.create(c.tag);r=c.tag.view;if(null!=r.reentrantLock)c=L;else if(r.reentrantLock=!0,v(c.tag,c,e),c.instance=w.normalize(r.call(c.state,c)),r.reentrantLock=null,null!=c.instance){if(c.instance===
c)throw Error("A view cannot return the vnode it received as arguments");e=h(a,c.instance,e,b,g);c.dom=c.instance.dom;c.domSize=null!=c.dom?c.instance.domSize:0;p(a,e,g);c=e}else c.domSize=0,c=L;return c}}function f(a,c,b){var n={caption:"table",thead:"table",tbody:"table",tfoot:"table",tr:"tbody",th:"tr",td:"tr",colgroup:"table",col:"colgroup"}[(c.children.match(/^\s*?<(\w+)/im)||[])[1]]||"div",n=q.createElement(n);n.innerHTML=c.children;c.dom=n.firstChild;c.domSize=n.childNodes.length;c=q.createDocumentFragment();
for(var e;e=n.firstChild;)c.appendChild(e);p(a,c,b);return c}function g(a,c,b,f,g,A,q){if(c!==b&&(null!=c||null!=b))if(null==c)d(a,b,0,b.length,g,A,void 0);else if(null==b)x(c,0,c.length,b);else{if(c.length===b.length){for(var n=!1,e=0;e<b.length;e++)if(null!=b[e]&&null!=c[e]){n=null==b[e].key&&null==c[e].key;break}if(n){for(e=0;e<c.length;e++)c[e]!==b[e]&&(null==c[e]&&null!=b[e]?h(a,b[e],g,q,m(c,e+1,A)):null==b[e]?x(c,e,e+1,b):l(a,c[e],b[e],g,m(c,e+1,A),!1,q));return}}if(!f)a:{if(null!=c.pool&&Math.abs(c.pool.length-
b.length)<=Math.abs(c.length-b.length)&&(f=b[0]&&b[0].children&&b[0].children.length||0,Math.abs((c.pool[0]&&c.pool[0].children&&c.pool[0].children.length||0)-f)<=Math.abs((c[0]&&c[0].children&&c[0].children.length||0)-f))){f=!0;break a}f=!1}f&&(c=c.concat(c.pool));for(var e=n=0,r=c.length-1,u=b.length-1,B;r>=n&&u>=e;){var t=c[n],y=b[e];if(t!==y||f)if(null==t)n++;else if(null==y)e++;else if(t.key===y.key)n++,e++,l(a,t,y,g,m(c,n,A),f,q),f&&t.tag===y.tag&&p(a,k(t),A);else if(t=c[r],t!==y||f)if(null==
t)r--;else if(null==y)e++;else if(t.key===y.key)l(a,t,y,g,m(c,r+1,A),f,q),(f||e<u)&&p(a,k(t),m(c,n,A)),r--,e++;else break;else r--,e++;else n++,e++}for(;r>=n&&u>=e;){t=c[r];y=b[u];if(t!==y||f)if(null==t)r--;else{if(null!=y)if(t.key===y.key)l(a,t,y,g,m(c,r+1,A),f,q),f&&t.tag===y.tag&&p(a,k(t),A),null!=t.dom&&(A=t.dom),r--;else{if(!B){B=c;var t=r,C={},v;for(v=0;v<t;v++){var w=B[v];null!=w&&(w=w.key,null!=w&&(C[w]=v))}B=C}null!=y&&(t=B[y.key],null!=t?(C=c[t],l(a,C,y,g,m(c,r+1,A),f,q),p(a,k(C),A),c[t].skip=
!0,null!=C.dom&&(A=C.dom)):A=h(a,y,g,void 0,A))}u--}else r--,u--;if(u<e)break}d(a,b,e,u+1,g,A,q);x(c,n,r+1,b)}}function l(a,c,e,d,p,q,t){var n=c.tag;if(n===e.tag){e.state=c.state;e.events=c.events;var r;var x;null!=e.attrs&&"function"===typeof e.attrs.onbeforeupdate&&(r=e.attrs.onbeforeupdate.call(e.state,e,c));"string"!==typeof e.tag&&"function"===typeof e.tag.onbeforeupdate&&(x=e.tag.onbeforeupdate.call(e.state,e,c));void 0===r&&void 0===x||r||x?r=!1:(e.dom=c.dom,e.domSize=c.domSize,e.instance=
c.instance,r=!0);if(!r)if(null!=e.attrs&&z(e.attrs,e,d,q),"string"===typeof n)switch(n){case "#":c.children.toString()!==e.children.toString()&&(c.dom.nodeValue=e.children);e.dom=c.dom;break;case "<":c.children!==e.children?(k(c),f(a,e,p)):(e.dom=c.dom,e.domSize=c.domSize);break;case "[":g(a,c.children,e.children,q,d,p,t);c=0;d=e.children;e.dom=null;if(null!=d){for(q=0;q<d.length;q++){var m=d[q];null!=m&&null!=m.dom&&(null==e.dom&&(e.dom=m.dom),c+=m.domSize||1)}1!==c&&(e.domSize=c)}break;default:a=
t;p=e.dom=c.dom;switch(e.tag){case "svg":a="http://www.w3.org/2000/svg";break;case "math":a="http://www.w3.org/1998/Math/MathML"}"textarea"===e.tag&&(null==e.attrs&&(e.attrs={}),null!=e.text&&(e.attrs.value=e.text,e.text=void 0));t=c.attrs;n=e.attrs;r=a;if(null!=n)for(m in n)y(e,m,t&&t[m],n[m],r);if(null!=t)for(m in t)null!=n&&m in n||("className"===m&&(m="class"),"o"!==m[0]||"n"!==m[1]||D(m)?"key"!==m&&e.dom.removeAttribute(m):K(e,m,void 0));null!=e.attrs&&null!=e.attrs.contenteditable?u(e):null!=
c.text&&null!=e.text&&""!==e.text?c.text.toString()!==e.text.toString()&&(c.dom.firstChild.nodeValue=e.text):(null!=c.text&&(c.children=[w("#",void 0,void 0,c.text,void 0,c.dom.firstChild)]),null!=e.text&&(e.children=[w("#",void 0,void 0,e.text,void 0,void 0)]),g(p,c.children,e.children,q,d,null,a))}else e.instance=w.normalize(e.tag.view.call(e.state,e)),z(e.tag,e,d,q),null!=e.instance?(null==c.instance?h(a,e.instance,d,t,p):l(a,c.instance,e.instance,d,p,q,t),e.dom=e.instance.dom,e.domSize=e.instance.domSize):
null!=c.instance?(b(c.instance,null),e.dom=void 0,e.domSize=0):(e.dom=c.dom,e.domSize=c.domSize)}else b(c,null),h(a,e,d,t,p)}function k(a){var c=a.domSize;if(null!=c||null==a.dom){var b=q.createDocumentFragment();if(0<c){for(a=a.dom;--c;)b.appendChild(a.nextSibling);b.insertBefore(a,b.firstChild)}return b}return a.dom}function m(a,c,b){for(;c<a.length;c++)if(null!=a[c]&&null!=a[c].dom)return a[c].dom;return b}function p(a,c,b){b&&b.parentNode?a.insertBefore(c,b):a.appendChild(c)}function u(a){var c=
a.children;if(null!=c&&1===c.length&&"<"===c[0].tag)c=c[0].children,a.dom.innerHTML!==c&&(a.dom.innerHTML=c);else if(null!=a.text||null!=c&&0!==c.length)throw Error("Child node of a contenteditable must be trusted");}function x(a,c,e,d){for(;c<e;c++){var n=a[c];null!=n&&(n.skip?n.skip=!1:b(n,d))}}function b(a,c){function b(){if(++n===d&&(B(a),a.dom)){var b=a.domSize||1;if(1<b)for(var e=a.dom;--b;){var f=e.nextSibling,g=f.parentNode;null!=g&&g.removeChild(f)}b=a.dom;e=b.parentNode;null!=e&&e.removeChild(b);
if(b=null!=c&&null==a.domSize)b=a.attrs,b=!(null!=b&&(b.oncreate||b.onupdate||b.onbeforeremove||b.onremove));b&&"string"===typeof a.tag&&(c.pool?c.pool.push(a):c.pool=[a])}}var d=1,n=0;if(a.attrs&&a.attrs.onbeforeremove){var f=a.attrs.onbeforeremove.call(a.state,a);null!=f&&"function"===typeof f.then&&(d++,f.then(b,b))}"string"!==typeof a.tag&&a.tag.onbeforeremove&&(f=a.tag.onbeforeremove.call(a.state,a),null!=f&&"function"===typeof f.then&&(d++,f.then(b,b)));b()}function B(a){a.attrs&&a.attrs.onremove&&
a.attrs.onremove.call(a.state,a);"string"!==typeof a.tag&&a.tag.onremove&&a.tag.onremove.call(a.state,a);if(null!=a.instance)B(a.instance);else if(a=a.children,Array.isArray(a))for(var c=0;c<a.length;c++){var b=a[c];null!=b&&B(b)}}function y(a,c,b,d,f){var e=a.dom;if("key"!==c&&"is"!==c&&(b!==d||"value"===c||"checked"===c||"selectedIndex"===c||"selected"===c&&a.dom===q.activeElement||"object"===typeof d)&&"undefined"!==typeof d&&!D(c)){var g=c.indexOf(":");if(-1<g&&"xlink"===c.substr(0,g))e.setAttributeNS("http://www.w3.org/1999/xlink",
c.slice(g+1),d);else if("o"===c[0]&&"n"===c[1]&&"function"===typeof d)K(a,c,d);else if("style"===c)if(a=b,a===d&&(e.style.cssText="",a=null),null==d)e.style.cssText="";else if("string"===typeof d)e.style.cssText=d;else{"string"===typeof a&&(e.style.cssText="");for(var n in d)e.style[n]=d[n];if(null!=a&&"string"!==typeof a)for(n in a)n in d||(e.style[n]="")}else c in e&&"href"!==c&&"list"!==c&&"form"!==c&&"width"!==c&&"height"!==c&&void 0===f&&!(a.attrs.is||-1<a.tag.indexOf("-"))?"input"===a.tag&&
"value"===c&&a.dom.value===d&&a.dom===q.activeElement||"select"===a.tag&&"value"===c&&a.dom.value===d&&a.dom===q.activeElement||"option"===a.tag&&"value"===c&&a.dom.value===d||(e[c]=d):"boolean"===typeof d?d?e.setAttribute(c,""):e.removeAttribute(c):e.setAttribute("className"===c?"class":c,d)}}function D(a){return"oninit"===a||"oncreate"===a||"onupdate"===a||"onremove"===a||"onbeforeremove"===a||"onbeforeupdate"===a}function K(a,c,b){var d=a.dom,e="function"!==typeof H?b:function(a){var c=b.call(d,
a);H.call(d,a);return c};if(c in d)d[c]="function"===typeof b?e:null;else{var f=c.slice(2);void 0===a.events&&(a.events={});a.events[c]!==e&&(null!=a.events[c]&&d.removeEventListener(f,a.events[c],!1),"function"===typeof b&&(a.events[c]=e,d.addEventListener(f,a.events[c],!1)))}}function v(a,c,b){"function"===typeof a.oninit&&a.oninit.call(c.state,c);"function"===typeof a.oncreate&&b.push(a.oncreate.bind(c.state,c))}function z(a,b,d,f){f?v(a,b,d):"function"===typeof a.onupdate&&d.push(a.onupdate.bind(b.state,
b))}var q=a.document,L=q.createDocumentFragment(),H;return{render:function(a,b){if(!a)throw Error("Ensure the DOM element being passed to m.route/m.mount/m.render is not undefined.");var c=[],d=q.activeElement;null==a.vnodes&&(a.textContent="");Array.isArray(b)||(b=[b]);g(a,a.vnodes,w.normalizeChildren(b),!1,c,null,void 0);a.vnodes=b;for(var f=0;f<c.length;f++)c[f]();q.activeElement!==d&&d.focus()},setEventCallback:function(a){return H=a}}},F=function(a){function d(a){a=f.indexOf(a);-1<a&&f.splice(a,
2)}function h(){for(var a=1;a<f.length;a+=2)f[a]()}a=M(a);a.setEventCallback(function(a){!1!==a.redraw&&h()});var f=[];return{subscribe:function(a,h){d(a);f.push(a,O(h))},unsubscribe:d,redraw:h,render:a.render}}(window);I.setCompletionCallback(F.redraw);z.mount=function(a){return function(d,h){if(null===h)a.render(d,[]),a.unsubscribe(d);else{if(null==h.view)throw Error("m.mount(element, component) expects a component, not a vnode");a.subscribe(d,function(){a.render(d,w(h))});a.redraw()}}}(F);var Q=
v,J=function(a){if(""===a||null==a)return{};"?"===a.charAt(0)&&(a=a.slice(1));a=a.split("&");for(var d={},h={},f=0;f<a.length;f++){var g=a[f].split("="),l=decodeURIComponent(g[0]),g=2===g.length?decodeURIComponent(g[1]):"";"true"===g?g=!0:"false"===g&&(g=!1);var k=l.split(/\]\[?|\[/),m=d;-1<l.indexOf("[")&&k.pop();for(var p=0;p<k.length;p++){var l=k[p],u=k[p+1],u=""==u||!isNaN(parseInt(u,10)),x=p===k.length-1;""===l&&(l=k.slice(0,p).join(),null==h[l]&&(h[l]=0),l=h[l]++);null==m[l]&&(m[l]=x?g:u?[]:
{});m=m[l]}}return d},R=function(a){function d(d){var f=a.location[d].replace(/(?:%[a-f89][a-f0-9])+/gim,decodeURIComponent);"pathname"===d&&"/"!==f[0]&&(f="/"+f);return f}function h(a){return function(){null==k&&(k=l(function(){k=null;a()}))}}function f(a,d,f){var b=a.indexOf("?"),g=a.indexOf("#"),k=-1<b?b:-1<g?g:a.length;if(-1<b){var b=J(a.slice(b+1,-1<g?g:a.length)),h;for(h in b)d[h]=b[h]}if(-1<g)for(h in d=J(a.slice(g+1)),d)f[h]=d[h];return a.slice(0,k)}var g="function"===typeof a.history.pushState,
l="function"===typeof setImmediate?setImmediate:setTimeout,k,m={prefix:"#!",getPath:function(){switch(m.prefix.charAt(0)){case "#":return d("hash").slice(m.prefix.length);case "?":return d("search").slice(m.prefix.length)+d("hash");default:return d("pathname").slice(m.prefix.length)+d("search")+d("hash")}},setPath:function(d,h,k){var b={},l={};d=f(d,b,l);if(null!=h){for(var p in h)b[p]=h[p];d=d.replace(/:([^\/]+)/g,function(a,d){delete b[d];return h[d]})}(p=E(b))&&(d+="?"+p);(l=E(l))&&(d+="#"+l);
g?(l=k?k.state:null,p=k?k.title:null,a.onpopstate(),k&&k.replace?a.history.replaceState(l,p,m.prefix+d):a.history.pushState(l,p,m.prefix+d)):a.location.href=m.prefix+d},defineRoutes:function(d,k,l){function b(){var b=m.getPath(),g={},h=f(b,g,g),p=a.history.state;if(null!=p)for(var x in p)g[x]=p[x];for(var u in d)if(p=new RegExp("^"+u.replace(/:[^\/]+?\.{3}/g,"(.*?)").replace(/:[^\/]+/g,"([^\\/]+)")+"/?$"),p.test(h)){h.replace(p,function(){for(var a=u.match(/:[^\/]+/g)||[],f=[].slice.call(arguments,
1,-2),h=0;h<a.length;h++)g[a[h].replace(/:|\./g,"")]=decodeURIComponent(f[h]);k(d[u],g,b,u)});return}l(b,g)}g?a.onpopstate=h(b):"#"===m.prefix.charAt(0)&&(a.onhashchange=b);b()}};return m};z.route=function(a,d){var h=R(a),f=function(a){return a},g,l,k,m,p,u=function(a,b,u){if(null==a)throw Error("Ensure the DOM element that was passed to `m.route` is not undefined");var x=function(){null!=g&&d.render(a,g(w(l,k.key,k)))},v=function(a){if(a!==b)h.setPath(b,null,{replace:!0});else throw Error("Could not resolve default route "+
b);};h.defineRoutes(u,function(a,b,d){var h=p=function(a,q){h===p&&(l=null!=q&&"function"===typeof q.view?q:"div",k=b,m=d,p=null,g=(a.render||f).bind(a),x())};a.view?h({},a):a.onmatch?Q.resolve(a.onmatch(b,d)).then(function(b){h(a,b)},v):h(a,"div")},v);d.subscribe(a,x)};u.set=function(a,b,d){null!=p&&(d={replace:!0});p=null;h.setPath(a,b,d)};u.get=function(){return m};u.prefix=function(a){h.prefix=a};u.link=function(a){a.dom.setAttribute("href",h.prefix+a.attrs.href);a.dom.onclick=function(a){a.ctrlKey||
a.metaKey||a.shiftKey||2===a.which||(a.preventDefault(),a.redraw=!1,a=this.getAttribute("href"),0===a.indexOf(h.prefix)&&(a=a.slice(h.prefix.length)),u.set(a,void 0,void 0))}};u.param=function(a){return"undefined"!==typeof k&&"undefined"!==typeof a?k[a]:k};return u}(window,F);z.withAttr=function(a,d,h){return function(f){d.call(h||this,a in f.currentTarget?f.currentTarget[a]:f.currentTarget.getAttribute(a))}};var S=M(window);z.render=S.render;z.redraw=F.redraw;z.request=I.request;z.jsonp=I.jsonp;
z.parseQueryString=J;z.buildQueryString=E;z.version="1.0.1";z.vnode=w;"undefined"!==typeof module?module.exports=z:window.m=z};
new function(){function x(a,d,h,f,g,l){return{tag:a,key:d,attrs:h,children:f,text:g,dom:l,domSize:void 0,state:{},events:void 0,instance:void 0,skip:!1}}function A(a){if(null==a||"string"!==typeof a&&"function"!==typeof a.view)throw Error("The selector must be either a string or a component.");if("string"===typeof a&&void 0===H[a]){for(var d,h,f=[],g={};d=O.exec(a);){var l=d[1],k=d[2];""===l&&""!==k?h=k:"#"===l?g.id=k:"."===l?f.push(k):"["===d[3][0]&&((l=d[6])&&(l=l.replace(/\\(["'])/g,"$1").replace(/\\\\/g,
"\\")),"class"===d[4]?f.push(l):g[d[4]]=l||!0)}0<f.length&&(g.className=f.join(" "));H[a]=function(a,d){var l=!1,b,f,r=a.className||a["class"],p;for(p in g)a[p]=g[p];void 0!==r&&(void 0!==a["class"]&&(a["class"]=void 0,a.className=r),void 0!==g.className&&(a.className=g.className+" "+r));for(p in a)if("key"!==p){l=!0;break}Array.isArray(d)&&1==d.length&&null!=d[0]&&"#"===d[0].tag?f=d[0].children:b=d;return x(h||"div",a.key,l?a:void 0,b,f,void 0)}}var p;null==arguments[1]||"object"===typeof arguments[1]&&
void 0===arguments[1].tag&&!Array.isArray(arguments[1])?(p=arguments[1],f=2):f=1;if(arguments.length===f+1)d=Array.isArray(arguments[f])?arguments[f]:[arguments[f]];else for(d=[];f<arguments.length;f++)d.push(arguments[f]);return"string"===typeof a?H[a](p||{},x.normalizeChildren(d)):x(a,p&&p.key,p||{},x.normalizeChildren(d),void 0,void 0)}function P(a){var d=0,h=null,f="function"===typeof requestAnimationFrame?requestAnimationFrame:setTimeout;return function(){var g=Date.now();0===d||16<=g-d?(d=g,
a()):null===h&&(h=f(function(){h=null;a();d=Date.now()},16-(g-d)))}}x.normalize=function(a){return Array.isArray(a)?x("[",void 0,void 0,x.normalizeChildren(a),void 0,void 0):null!=a&&"object"!==typeof a?x("#",void 0,void 0,!1===a?"":a,void 0,void 0):a};x.normalizeChildren=function(a){for(var d=0;d<a.length;d++)a[d]=x.normalize(a[d]);return a};var O=/(?:(^|#|\.)([^#\.\[\]]+))|(\[(.+?)(?:\s*=\s*("|'|)((?:\\["'\]]|.)*?)\5)?\])/g,H={};A.trust=function(a){null==a&&(a="");return x("<",void 0,void 0,a,void 0,
void 0)};A.fragment=function(a,d){return x("[",a.key,a,x.normalizeChildren(d),void 0,void 0)};var w=function(a){function d(a,b){return function z(d){var k;try{if(!b||null==d||"object"!==typeof d&&"function"!==typeof d||"function"!==typeof(k=d.then))t(function(){b||0!==a.length||console.error("Possible unhandled promise rejection:",d);for(var f=0;f<a.length;f++)a[f](d);g.length=0;l.length=0;r.state=b;r.retry=function(){z(d)}});else{if(d===f)throw new TypeError("Promise can't be resolved w/ itself");
h(k.bind(d))}}catch(Q){p(Q)}}}function h(a){function b(b){return function(a){0<d++||b(a)}}var d=0,f=b(p);try{a(b(k),f)}catch(D){f(D)}}if(!(this instanceof w))throw Error("Promise must be called with `new`");if("function"!==typeof a)throw new TypeError("executor must be a function");var f=this,g=[],l=[],k=d(g,!0),p=d(l,!1),r=f._instance={resolvers:g,rejectors:l},t="function"===typeof setImmediate?setImmediate:setTimeout;h(a)};w.prototype.then=function(a,d){function h(a,d,h,k){d.push(function(b){if("function"!==
typeof a)h(b);else try{g(a(b))}catch(u){l&&l(u)}});"function"===typeof f.retry&&k===f.state&&f.retry()}var f=this._instance,g,l,k=new w(function(a,d){g=a;l=d});h(a,f.resolvers,g,!0);h(d,f.rejectors,l,!1);return k};w.prototype["catch"]=function(a){return this.then(null,a)};w.resolve=function(a){return a instanceof w?a:new w(function(d){d(a)})};w.reject=function(a){return new w(function(d,h){h(a)})};w.all=function(a){return new w(function(d,h){var f=a.length,g=0,l=[];if(0===a.length)d([]);else for(var k=
0;k<a.length;k++)(function(k){function r(a){g++;l[k]=a;g===f&&d(l)}null==a[k]||"object"!==typeof a[k]&&"function"!==typeof a[k]||"function"!==typeof a[k].then?r(a[k]):a[k].then(r,h)})(k)})};w.race=function(a){return new w(function(d,h){for(var f=0;f<a.length;f++)a[f].then(d,h)})};"undefined"!==typeof window?("undefined"===typeof window.Promise&&(window.Promise=w),w=window.Promise):"undefined"!==typeof global&&("undefined"===typeof global.Promise&&(global.Promise=w),w=global.Promise);var F=function(a){function d(a,
f){if(Array.isArray(f))for(var g=0;g<f.length;g++)d(a+"["+g+"]",f[g]);else if("[object Object]"===Object.prototype.toString.call(f))for(g in f)d(a+"["+g+"]",f[g]);else h.push(encodeURIComponent(a)+(null!=f&&""!==f?"="+encodeURIComponent(f):""))}if("[object Object]"!==Object.prototype.toString.call(a))return"";var h=[],f;for(f in a)d(f,a[f]);return h.join("&")},J=function(a,d){function h(){function b(){0===--a&&"function"===typeof q&&q()}var a=0;return function D(d){var f=d.then;d.then=function(){a++;
var g=f.apply(d,arguments);g.then(b,function(d){b();if(0===a)throw d;});return D(g)};return d}}function f(b,a){if("string"===typeof b){var d=b;b=a||{};null==b.url&&(b.url=d)}return b}function g(b,a){if(null==a)return b;for(var d=b.match(/:[^\/]+/gi)||[],f=0;f<d.length;f++){var g=d[f].slice(1);null!=a[g]&&(b=b.replace(d[f],a[g]))}return b}function l(b,a){var d=F(a);if(""!==d){var f=0>b.indexOf("?")?"?":"&";b+=f+d}return b}function k(b){try{return""!==b?JSON.parse(b):null}catch(u){throw Error(b);}}
function p(b){return b.responseText}function r(b,a){if("function"===typeof b)if(Array.isArray(a))for(var d=0;d<a.length;d++)a[d]=new b(a[d]);else return new b(a);return a}var t=0,q;return{request:function(b,q){var t=h();b=f(b,q);var u=new d(function(d,f){null==b.method&&(b.method="GET");b.method=b.method.toUpperCase();var h="boolean"===typeof b.useBody?b.useBody:"GET"!==b.method&&"TRACE"!==b.method;"function"!==typeof b.serialize&&(b.serialize="undefined"!==typeof FormData&&b.data instanceof FormData?
function(a){return a}:JSON.stringify);"function"!==typeof b.deserialize&&(b.deserialize=k);"function"!==typeof b.extract&&(b.extract=p);b.url=g(b.url,b.data);h?b.data=b.serialize(b.data):b.url=l(b.url,b.data);var n=new a.XMLHttpRequest;n.open(b.method,b.url,"boolean"===typeof b.async?b.async:!0,"string"===typeof b.user?b.user:void 0,"string"===typeof b.password?b.password:void 0);b.serialize===JSON.stringify&&h&&n.setRequestHeader("Content-Type","application/json; charset=utf-8");b.deserialize===
k&&n.setRequestHeader("Accept","application/json, text/*");b.withCredentials&&(n.withCredentials=b.withCredentials);for(var q in b.headers)({}).hasOwnProperty.call(b.headers,q)&&n.setRequestHeader(q,b.headers[q]);"function"===typeof b.config&&(n=b.config(n,b)||n);n.onreadystatechange=function(){if(n.status&&4===n.readyState)try{var a=b.extract!==p?b.extract(n,b):b.deserialize(b.extract(n,b));if(200<=n.status&&300>n.status||304===n.status)d(r(b.type,a));else{var m=Error(n.responseText),c;for(c in a)m[c]=
a[c];f(m)}}catch(e){f(e)}};h&&null!=b.data?n.send(b.data):n.send()});return!0===b.background?u:t(u)},jsonp:function(b,k){var p=h();b=f(b,k);var q=new d(function(d,f){var h=b.callbackName||"_mithril_"+Math.round(1E16*Math.random())+"_"+t++,k=a.document.createElement("script");a[h]=function(f){k.parentNode.removeChild(k);d(r(b.type,f));delete a[h]};k.onerror=function(){k.parentNode.removeChild(k);f(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?q:p(q)},setCompletionCallback:function(a){q=a}}}(window,w),N=function(a){function d(a,c,e,b,d,f,g){for(;e<b;e++){var m=c[e];null!=m&&h(a,m,d,g,f)}}function h(a,c,e,b,g){var m=c.tag;null!=c.attrs&&w(c.attrs,c,e);if("string"===typeof m)switch(m){case "#":return c.dom=n.createTextNode(c.children),r(a,c.dom,g),c.dom;case "<":return f(a,c,g);case "[":var v=n.createDocumentFragment();null!=c.children&&
(m=c.children,d(v,m,0,m.length,e,null,b));c.dom=v.firstChild;c.domSize=v.childNodes.length;r(a,v,g);return v;default:var k=c.tag;switch(c.tag){case "svg":b="http://www.w3.org/2000/svg";break;case "math":b="http://www.w3.org/1998/Math/MathML"}var l=(m=c.attrs)&&m.is,k=b?l?n.createElementNS(b,k,{is:l}):n.createElementNS(b,k):l?n.createElement(k,{is:l}):n.createElement(k);c.dom=k;if(null!=m)for(v in l=b,m)z(c,v,null,m[v],l);r(a,k,g);null!=c.attrs&&null!=c.attrs.contenteditable?t(c):(null!=c.text&&(""!==
c.text?k.textContent=c.text:c.children=[x("#",void 0,void 0,c.text,void 0,void 0)]),null!=c.children&&(a=c.children,d(k,a,0,a.length,e,null,b),a=c.attrs,"select"===c.tag&&null!=a&&("value"in a&&z(c,"value",null,a.value,void 0),"selectedIndex"in a&&z(c,"selectedIndex",null,a.selectedIndex,void 0))));return k}else{c.state=Object.create(c.tag);v=c.tag.view;if(null!=v.reentrantLock)c=M;else if(v.reentrantLock=!0,w(c.tag,c,e),c.instance=x.normalize(v.call(c.state,c)),v.reentrantLock=null,null!=c.instance){if(c.instance===
c)throw Error("A view cannot return the vnode it received as arguments");e=h(a,c.instance,e,b,g);c.dom=c.instance.dom;c.domSize=null!=c.dom?c.instance.domSize:0;r(a,e,g);c=e}else c.domSize=0,c=M;return c}}function f(a,c,b){var m={caption:"table",thead:"table",tbody:"table",tfoot:"table",tr:"tbody",th:"tr",td:"tr",colgroup:"table",col:"colgroup"}[(c.children.match(/^\s*?<(\w+)/im)||[])[1]]||"div",m=n.createElement(m);m.innerHTML=c.children;c.dom=m.firstChild;c.domSize=m.childNodes.length;c=n.createDocumentFragment();
for(var e;e=m.firstChild;)c.appendChild(e);r(a,c,b);return c}function g(a,c,b,f,g,B,n){if(c!==b&&(null!=c||null!=b))if(null==c)d(a,b,0,b.length,g,B,void 0);else if(null==b)q(c,0,c.length,b);else{if(c.length===b.length){for(var m=!1,e=0;e<b.length;e++)if(null!=b[e]&&null!=c[e]){m=null==b[e].key&&null==c[e].key;break}if(m){for(e=0;e<c.length;e++)c[e]!==b[e]&&(null==c[e]&&null!=b[e]?h(a,b[e],g,n,p(c,e+1,B)):null==b[e]?q(c,e,e+1,b):l(a,c[e],b[e],g,p(c,e+1,B),f,n));return}}if(!f)a:{if(null!=c.pool&&Math.abs(c.pool.length-
b.length)<=Math.abs(c.length-b.length)&&(f=b[0]&&b[0].children&&b[0].children.length||0,Math.abs((c.pool[0]&&c.pool[0].children&&c.pool[0].children.length||0)-f)<=Math.abs((c[0]&&c[0].children&&c[0].children.length||0)-f))){f=!0;break a}f=!1}if(f){var v=c.pool;c=c.concat(c.pool)}for(var e=m=0,t=c.length-1,u=b.length-1,E;t>=m&&u>=e;){var y=c[m],z=b[e];if(y!==z||f)if(null==y)m++;else if(null==z)e++;else if(y.key===z.key){var C=null!=v&&m>=c.length-v.length||null==v&&f;m++;e++;l(a,y,z,g,p(c,m,B),C,n);
f&&y.tag===z.tag&&r(a,k(y),B)}else if(y=c[t],y!==z||f)if(null==y)t--;else if(null==z)e++;else if(y.key===z.key)C=null!=v&&t>=c.length-v.length||null==v&&f,l(a,y,z,g,p(c,t+1,B),C,n),(f||e<u)&&r(a,k(y),p(c,m,B)),t--,e++;else break;else t--,e++;else m++,e++}for(;t>=m&&u>=e;){y=c[t];z=b[u];if(y!==z||f)if(null==y)t--;else{if(null!=z)if(y.key===z.key)C=null!=v&&t>=c.length-v.length||null==v&&f,l(a,y,z,g,p(c,t+1,B),C,n),f&&y.tag===z.tag&&r(a,k(y),B),null!=y.dom&&(B=y.dom),t--;else{if(!E){E=c;var y=t,C={},
w;for(w=0;w<y;w++){var x=E[w];null!=x&&(x=x.key,null!=x&&(C[x]=w))}E=C}null!=z&&(y=E[z.key],null!=y?(C=c[y],l(a,C,z,g,p(c,t+1,B),f,n),r(a,k(C),B),c[y].skip=!0,null!=C.dom&&(B=C.dom)):B=h(a,z,g,void 0,B))}u--}else t--,u--;if(u<e)break}d(a,b,e,u+1,g,B,n);q(c,m,t+1,b)}}function l(a,c,e,d,r,n,q){var m=c.tag;if(m===e.tag){e.state=c.state;e.events=c.events;var v;var p;null!=e.attrs&&"function"===typeof e.attrs.onbeforeupdate&&(v=e.attrs.onbeforeupdate.call(e.state,e,c));"string"!==typeof e.tag&&"function"===
typeof e.tag.onbeforeupdate&&(p=e.tag.onbeforeupdate.call(e.state,e,c));void 0===v&&void 0===p||v||p?v=!1:(e.dom=c.dom,e.domSize=c.domSize,e.instance=c.instance,v=!0);if(!v)if(null!=e.attrs&&A(e.attrs,e,d,n),"string"===typeof m)switch(m){case "#":c.children.toString()!==e.children.toString()&&(c.dom.nodeValue=e.children);e.dom=c.dom;break;case "<":c.children!==e.children?(k(c),f(a,e,r)):(e.dom=c.dom,e.domSize=c.domSize);break;case "[":g(a,c.children,e.children,n,d,r,q);c=0;d=e.children;e.dom=null;
if(null!=d){for(n=0;n<d.length;n++){var u=d[n];null!=u&&null!=u.dom&&(null==e.dom&&(e.dom=u.dom),c+=u.domSize||1)}1!==c&&(e.domSize=c)}break;default:a=q;r=e.dom=c.dom;switch(e.tag){case "svg":a="http://www.w3.org/2000/svg";break;case "math":a="http://www.w3.org/1998/Math/MathML"}"textarea"===e.tag&&(null==e.attrs&&(e.attrs={}),null!=e.text&&(e.attrs.value=e.text,e.text=void 0));q=c.attrs;m=e.attrs;v=a;if(null!=m)for(u in m)z(e,u,q&&q[u],m[u],v);if(null!=q)for(u in q)null!=m&&u in m||("className"===
u&&(u="class"),"o"!==u[0]||"n"!==u[1]||D(u)?"key"!==u&&e.dom.removeAttribute(u):L(e,u,void 0));null!=e.attrs&&null!=e.attrs.contenteditable?t(e):null!=c.text&&null!=e.text&&""!==e.text?c.text.toString()!==e.text.toString()&&(c.dom.firstChild.nodeValue=e.text):(null!=c.text&&(c.children=[x("#",void 0,void 0,c.text,void 0,c.dom.firstChild)]),null!=e.text&&(e.children=[x("#",void 0,void 0,e.text,void 0,void 0)]),g(r,c.children,e.children,n,d,null,a))}else e.instance=x.normalize(e.tag.view.call(e.state,
e)),A(e.tag,e,d,n),null!=e.instance?(null==c.instance?h(a,e.instance,d,q,r):l(a,c.instance,e.instance,d,r,n,q),e.dom=e.instance.dom,e.domSize=e.instance.domSize):null!=c.instance?(b(c.instance,null),e.dom=void 0,e.domSize=0):(e.dom=c.dom,e.domSize=c.domSize)}else b(c,null),h(a,e,d,q,r)}function k(a){var c=a.domSize;if(null!=c||null==a.dom){var b=n.createDocumentFragment();if(0<c){for(a=a.dom;--c;)b.appendChild(a.nextSibling);b.insertBefore(a,b.firstChild)}return b}return a.dom}function p(a,c,b){for(;c<
a.length;c++)if(null!=a[c]&&null!=a[c].dom)return a[c].dom;return b}function r(a,c,b){b&&b.parentNode?a.insertBefore(c,b):a.appendChild(c)}function t(a){var c=a.children;if(null!=c&&1===c.length&&"<"===c[0].tag)c=c[0].children,a.dom.innerHTML!==c&&(a.dom.innerHTML=c);else if(null!=a.text||null!=c&&0!==c.length)throw Error("Child node of a contenteditable must be trusted");}function q(a,c,e,d){for(;c<e;c++){var m=a[c];null!=m&&(m.skip?m.skip=!1:b(m,d))}}function b(a,c){function b(){if(++m===d&&(u(a),
a.dom)){var b=a.domSize||1;if(1<b)for(var e=a.dom;--b;){var f=e.nextSibling,g=f.parentNode;null!=g&&g.removeChild(f)}b=a.dom;e=b.parentNode;null!=e&&e.removeChild(b);if(b=null!=c&&null==a.domSize)b=a.attrs,b=!(null!=b&&(b.oncreate||b.onupdate||b.onbeforeremove||b.onremove));b&&"string"===typeof a.tag&&(c.pool?c.pool.push(a):c.pool=[a])}}var d=1,m=0;if(a.attrs&&a.attrs.onbeforeremove){var f=a.attrs.onbeforeremove.call(a.state,a);null!=f&&"function"===typeof f.then&&(d++,f.then(b,b))}"string"!==typeof a.tag&&
a.tag.onbeforeremove&&(f=a.tag.onbeforeremove.call(a.state,a),null!=f&&"function"===typeof f.then&&(d++,f.then(b,b)));b()}function u(a){a.attrs&&a.attrs.onremove&&a.attrs.onremove.call(a.state,a);"string"!==typeof a.tag&&a.tag.onremove&&a.tag.onremove.call(a.state,a);if(null!=a.instance)u(a.instance);else if(a=a.children,Array.isArray(a))for(var c=0;c<a.length;c++){var b=a[c];null!=b&&u(b)}}function z(a,c,b,d,f){var e=a.dom;if("key"!==c&&"is"!==c&&(b!==d||"value"===c||"checked"===c||"selectedIndex"===
c||"selected"===c&&a.dom===n.activeElement||"object"===typeof d)&&"undefined"!==typeof d&&!D(c)){var g=c.indexOf(":");if(-1<g&&"xlink"===c.substr(0,g))e.setAttributeNS("http://www.w3.org/1999/xlink",c.slice(g+1),d);else if("o"===c[0]&&"n"===c[1]&&"function"===typeof d)L(a,c,d);else if("style"===c)if(a=b,a===d&&(e.style.cssText="",a=null),null==d)e.style.cssText="";else if("string"===typeof d)e.style.cssText=d;else{"string"===typeof a&&(e.style.cssText="");for(var m in d)e.style[m]=d[m];if(null!=a&&
"string"!==typeof a)for(m in a)m in d||(e.style[m]="")}else c in e&&"href"!==c&&"list"!==c&&"form"!==c&&"width"!==c&&"height"!==c&&void 0===f&&!(a.attrs.is||-1<a.tag.indexOf("-"))?"input"===a.tag&&"value"===c&&a.dom.value===d&&a.dom===n.activeElement||"select"===a.tag&&"value"===c&&a.dom.value===d&&a.dom===n.activeElement||"option"===a.tag&&"value"===c&&a.dom.value===d||(e[c]=d):"boolean"===typeof d?d?e.setAttribute(c,""):e.removeAttribute(c):e.setAttribute("className"===c?"class":c,d)}}function D(a){return"oninit"===
a||"oncreate"===a||"onupdate"===a||"onremove"===a||"onbeforeremove"===a||"onbeforeupdate"===a}function L(a,c,b){var d=a.dom,e="function"!==typeof I?b:function(a){var c=b.call(d,a);I.call(d,a);return c};if(c in d)d[c]="function"===typeof b?e:null;else{var f=c.slice(2);void 0===a.events&&(a.events={});a.events[c]!==e&&(null!=a.events[c]&&d.removeEventListener(f,a.events[c],!1),"function"===typeof b&&(a.events[c]=e,d.addEventListener(f,a.events[c],!1)))}}function w(a,c,b){"function"===typeof a.oninit&&
a.oninit.call(c.state,c);"function"===typeof a.oncreate&&b.push(a.oncreate.bind(c.state,c))}function A(a,c,b,d){d?w(a,c,b):"function"===typeof a.onupdate&&b.push(a.onupdate.bind(c.state,c))}var n=a.document,M=n.createDocumentFragment(),I;return{render:function(a,c){if(!a)throw Error("Ensure the DOM element being passed to m.route/m.mount/m.render is not undefined.");var b=[],d=n.activeElement;null==a.vnodes&&(a.textContent="");Array.isArray(c)||(c=[c]);g(a,a.vnodes,x.normalizeChildren(c),!1,b,null,
void 0);a.vnodes=c;for(var f=0;f<b.length;f++)b[f]();n.activeElement!==d&&d.focus()},setEventCallback:function(a){return I=a}}},G=function(a){function d(a){a=f.indexOf(a);-1<a&&f.splice(a,2)}function h(){for(var a=1;a<f.length;a+=2)f[a]()}a=N(a);a.setEventCallback(function(a){!1!==a.redraw&&h()});var f=[];return{subscribe:function(a,h){d(a);f.push(a,P(h))},unsubscribe:d,redraw:h,render:a.render}}(window);J.setCompletionCallback(G.redraw);A.mount=function(a){return function(d,h){if(null===h)a.render(d,
[]),a.unsubscribe(d);else{if(null==h.view)throw Error("m.mount(element, component) expects a component, not a vnode");a.subscribe(d,function(){a.render(d,x(h))});a.redraw()}}}(G);var R=w,K=function(a){if(""===a||null==a)return{};"?"===a.charAt(0)&&(a=a.slice(1));a=a.split("&");for(var d={},h={},f=0;f<a.length;f++){var g=a[f].split("="),l=decodeURIComponent(g[0]),g=2===g.length?decodeURIComponent(g[1]):"";"true"===g?g=!0:"false"===g&&(g=!1);var k=l.split(/\]\[?|\[/),p=d;-1<l.indexOf("[")&&k.pop();
for(var r=0;r<k.length;r++){var l=k[r],t=k[r+1],t=""==t||!isNaN(parseInt(t,10)),q=r===k.length-1;""===l&&(l=k.slice(0,r).join(),null==h[l]&&(h[l]=0),l=h[l]++);null==p[l]&&(p[l]=q?g:t?[]:{});p=p[l]}}return d},S=function(a){function d(d){var f=a.location[d].replace(/(?:%[a-f89][a-f0-9])+/gim,decodeURIComponent);"pathname"===d&&"/"!==f[0]&&(f="/"+f);return f}function h(a){return function(){null==k&&(k=l(function(){k=null;a()}))}}function f(a,d,f){var b=a.indexOf("?"),g=a.indexOf("#"),k=-1<b?b:-1<g?g:
a.length;if(-1<b){var b=K(a.slice(b+1,-1<g?g:a.length)),h;for(h in b)d[h]=b[h]}if(-1<g)for(h in d=K(a.slice(g+1)),d)f[h]=d[h];return a.slice(0,k)}var g="function"===typeof a.history.pushState,l="function"===typeof setImmediate?setImmediate:setTimeout,k,p={prefix:"#!",getPath:function(){switch(p.prefix.charAt(0)){case "#":return d("hash").slice(p.prefix.length);case "?":return d("search").slice(p.prefix.length)+d("hash");default:return d("pathname").slice(p.prefix.length)+d("search")+d("hash")}},setPath:function(d,
h,k){var b={},l={};d=f(d,b,l);if(null!=h){for(var q in h)b[q]=h[q];d=d.replace(/:([^\/]+)/g,function(a,d){delete b[d];return h[d]})}(q=F(b))&&(d+="?"+q);(l=F(l))&&(d+="#"+l);g?(l=k?k.state:null,q=k?k.title:null,a.onpopstate(),k&&k.replace?a.history.replaceState(l,q,p.prefix+d):a.history.pushState(l,q,p.prefix+d)):a.location.href=p.prefix+d},defineRoutes:function(d,k,l){function b(){var b=p.getPath(),g={},h=f(b,g,g),q=a.history.state;if(null!=q)for(var r in q)g[r]=q[r];for(var t in d)if(q=new RegExp("^"+
t.replace(/:[^\/]+?\.{3}/g,"(.*?)").replace(/:[^\/]+/g,"([^\\/]+)")+"/?$"),q.test(h)){h.replace(q,function(){for(var a=t.match(/:[^\/]+/g)||[],f=[].slice.call(arguments,1,-2),h=0;h<a.length;h++)g[a[h].replace(/:|\./g,"")]=decodeURIComponent(f[h]);k(d[t],g,b,t)});return}l(b,g)}g?a.onpopstate=h(b):"#"===p.prefix.charAt(0)&&(a.onhashchange=b);b()}};return p};A.route=function(a,d){var h=S(a),f=function(a){return a},g,l,k,p,r,t=function(a,b,t){if(null==a)throw Error("Ensure the DOM element that was passed to `m.route` is not undefined");
var q=function(){null!=g&&d.render(a,g(x(l,k.key,k)))},u=function(a){if(a!==b)h.setPath(b,null,{replace:!0});else throw Error("Could not resolve default route "+b);};h.defineRoutes(t,function(a,b,d){var h=r=function(a,n){h===r&&(l=null!=n&&"function"===typeof n.view?n:"div",k=b,p=d,r=null,g=(a.render||f).bind(a),q())};a.view?h({},a):a.onmatch?R.resolve(a.onmatch(b,d)).then(function(b){h(a,b)},u):h(a,"div")},u);d.subscribe(a,q)};t.set=function(a,b,d){null!=r&&(d={replace:!0});r=null;h.setPath(a,b,
d)};t.get=function(){return p};t.prefix=function(a){h.prefix=a};t.link=function(a){a.dom.setAttribute("href",h.prefix+a.attrs.href);a.dom.onclick=function(a){a.ctrlKey||a.metaKey||a.shiftKey||2===a.which||(a.preventDefault(),a.redraw=!1,a=this.getAttribute("href"),0===a.indexOf(h.prefix)&&(a=a.slice(h.prefix.length)),t.set(a,void 0,void 0))}};t.param=function(a){return"undefined"!==typeof k&&"undefined"!==typeof a?k[a]:k};return t}(window,G);A.withAttr=function(a,d,h){return function(f){d.call(h||
this,a in f.currentTarget?f.currentTarget[a]:f.currentTarget.getAttribute(a))}};var T=N(window);A.render=T.render;A.redraw=G.redraw;A.request=J.request;A.jsonp=J.jsonp;A.parseQueryString=K;A.buildQueryString=F;A.version="1.0.1";A.vnode=x;"undefined"!==typeof module?module.exports=A:window.m=A};

View file

@ -147,7 +147,10 @@ module.exports = function($window) {
}
}
recycling = recycling || isRecyclable(old, vnodes)
if (recycling) old = old.concat(old.pool)
if (recycling) {
var pool = old.pool
old = old.concat(old.pool)
}
var oldStart = 0, start = 0, oldEnd = old.length - 1, end = vnodes.length - 1, map
while (oldEnd >= oldStart && end >= start) {
@ -156,8 +159,9 @@ module.exports = function($window) {
else if (o == null) oldStart++
else if (v == null) start++
else if (o.key === v.key) {
var shouldRecycle = (pool != null && oldStart >= old.length - pool.length) || ((pool == null) && recycling)
oldStart++, start++
updateNode(parent, o, v, hooks, getNextSibling(old, oldStart, nextSibling), recycling, ns)
updateNode(parent, o, v, hooks, getNextSibling(old, oldStart, nextSibling), shouldRecycle, ns)
if (recycling && o.tag === v.tag) insertNode(parent, toFragment(o), nextSibling)
}
else {
@ -166,7 +170,8 @@ module.exports = function($window) {
else if (o == null) oldEnd--
else if (v == null) start++
else if (o.key === v.key) {
updateNode(parent, o, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), recycling, ns)
var shouldRecycle = (pool != null && oldEnd >= old.length - pool.length) || ((pool == null) && recycling)
updateNode(parent, o, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), shouldRecycle, ns)
if (recycling || start < end) insertNode(parent, toFragment(o), getNextSibling(old, oldStart, nextSibling))
oldEnd--, start++
}
@ -179,7 +184,8 @@ module.exports = function($window) {
else if (o == null) oldEnd--
else if (v == null) end--
else if (o.key === v.key) {
updateNode(parent, o, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), recycling, ns)
var shouldRecycle = (pool != null && oldEnd >= old.length - pool.length) || ((pool == null) && recycling)
updateNode(parent, o, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), shouldRecycle, ns)
if (recycling && o.tag === v.tag) insertNode(parent, toFragment(o), nextSibling)
if (o.dom != null) nextSibling = o.dom
oldEnd--, end--
@ -190,6 +196,7 @@ module.exports = function($window) {
var oldIndex = map[v.key]
if (oldIndex != null) {
var movable = old[oldIndex]
var shouldRecycle = (pool != null && oldIndex >= old.length - pool.length) || ((pool == null) && recycling)
updateNode(parent, movable, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), recycling, ns)
insertNode(parent, toFragment(movable), nextSibling)
old[oldIndex].skip = true

View file

@ -113,4 +113,40 @@ o.spec("render", function() {
o(updateB.callCount).equals(0)
o(removeB.callCount).equals(1)
})
o.only("update lifecycle methods work on children of recycled keyed", function() {
var createA = o.spy()
var updateA = o.spy()
var removeA = o.spy()
var createB = o.spy()
var updateB = o.spy()
var removeB = o.spy()
var a = function() {
return {tag: "div", key: 1, children: [
{tag: "div", attrs: {oncreate: createA, onupdate: updateA, onremove: removeA}},
]}
}
var b = function() {
return {tag: "div", key: 2, children: [
{tag: "div", attrs: {oncreate: createB, onupdate: updateB, onremove: removeB}},
]}
}
render(root, a())
render(root, a())
o(createA.callCount).equals(1)
o(updateA.callCount).equals(1)
o(removeA.callCount).equals(0)
render(root, b())
o(createA.callCount).equals(1)
o(updateA.callCount).equals(1)
o(removeA.callCount).equals(1)
render(root, a())
render(root, a())
o(createA.callCount).equals(2)
o(updateA.callCount).equals(2)
o(removeA.callCount).equals(1)
})
})