fix diff bug when array is sparse, item type and position and array length change
This commit is contained in:
parent
0c94bae845
commit
8eb61a12ab
4 changed files with 73 additions and 45 deletions
12
mithril.js
12
mithril.js
|
|
@ -472,7 +472,9 @@ var _13 = function($window) {
|
|||
while (oldEnd >= oldStart && end >= start) {
|
||||
var o = old[oldStart], v = vnodes[start]
|
||||
if (o === v && !recycling) oldStart++, start++
|
||||
else if (o != null && v != null && o.key === v.key) {
|
||||
else if (o == null) oldStart++
|
||||
else if (v == null) start++
|
||||
else if (o.key === v.key) {
|
||||
oldStart++, start++
|
||||
updateNode(parent, o, v, hooks, getNextSibling(old, oldStart, nextSibling), recycling, ns)
|
||||
if (recycling && o.tag === v.tag) insertNode(parent, toFragment(o), nextSibling)
|
||||
|
|
@ -480,7 +482,9 @@ var _13 = function($window) {
|
|||
else {
|
||||
var o = old[oldEnd]
|
||||
if (o === v && !recycling) oldEnd--, start++
|
||||
else if (o != null && v != null && o.key === v.key) {
|
||||
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)
|
||||
if (recycling || start < end) insertNode(parent, toFragment(o), getNextSibling(old, oldStart, nextSibling))
|
||||
oldEnd--, start++
|
||||
|
|
@ -491,7 +495,9 @@ var _13 = function($window) {
|
|||
while (oldEnd >= oldStart && end >= start) {
|
||||
var o = old[oldEnd], v = vnodes[end]
|
||||
if (o === v && !recycling) oldEnd--, end--
|
||||
else if (o != null && v != null && o.key === v.key) {
|
||||
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)
|
||||
if (recycling && o.tag === v.tag) insertNode(parent, toFragment(o), nextSibling)
|
||||
if (o.dom != null) nextSibling = o.dom
|
||||
|
|
|
|||
78
mithril.min.js
vendored
78
mithril.min.js
vendored
|
|
@ -1,40 +1,40 @@
|
|||
new function(){function l(a,b,k,d,n,h){return{tag:a,key:b,attrs:k,children:d,text:n,dom:h,domSize:void 0,state:{},events:void 0,instance:void 0,skip:!1}}function t(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===G[a]){for(var b,k,d=[],n={};b=N.exec(a);){var h=b[1],v=b[2];""===h&&""!==v?k=v:"#"===h?n.id=v:"."===h?d.push(v):"["===b[3][0]&&((h=b[6])&&(h=h.replace(/\\(["'])/g,"$1").replace(/\\\\/g,"\\")),
|
||||
"class"===b[4]?d.push(h):n[b[4]]=h||!0)}0<d.length&&(n.className=d.join(" "));G[a]=function(a,b){var d=!1,h,f,x=a.className||a["class"],m;for(m in n)a[m]=n[m];void 0!==x&&(void 0!==a["class"]&&(a["class"]=void 0,a.className=x),void 0!==n.className&&(a.className=n.className+" "+x));for(m in a)if("key"!==m){d=!0;break}b instanceof Array&&1==b.length&&null!=b[0]&&"#"===b[0].tag?f=b[0].children:h=b;return l(k||"div",a.key,d?a:void 0,h,f,void 0)}}var q;null!=arguments[1]&&("object"!==typeof arguments[1]||
|
||||
void 0!==arguments[1].tag||arguments[1]instanceof Array)?d=1:(q=arguments[1],d=2);if(arguments.length===d+1)b=arguments[d]instanceof Array?arguments[d]:[arguments[d]];else for(b=[];d<arguments.length;d++)b.push(arguments[d]);return"string"===typeof a?G[a](q||{},l.normalizeChildren(b)):l(a,q&&q.key,q||{},l.normalizeChildren(b),void 0,void 0)}l.normalize=function(a){return a instanceof Array?l("[",void 0,void 0,l.normalizeChildren(a),void 0,void 0):null!=a&&"object"!==typeof a?l("#",void 0,void 0,a,
|
||||
void 0,void 0):a};l.normalizeChildren=function(a){for(var b=0;b<a.length;b++)a[b]=l.normalize(a[b]);return a};var N=/(?:(^|#|\.)([^#\.\[\]]+))|(\[(.+?)(?:\s*=\s*("|'|)((?:\\["'\]]|.)*?)\5)?\])/g,G={};t.trust=function(a){null==a&&(a="");return l("<",void 0,void 0,a,void 0,void 0)};t.fragment=function(a,b){return l("[",a.key,a,l.normalizeChildren(b),void 0,void 0)};var z=function(a){function b(a,b){return function x(m){var p;try{if(!b||null==m||"object"!==typeof m&&"function"!==typeof m||"function"!==
|
||||
typeof(p=m.then))l(function(){b||0!==a.length||console.error("Possible unhandled promise rejection:",m);for(var d=0;d<a.length;d++)a[d](m);n.length=0;h.length=0;r.state=b;r.retry=function(){x(m)}});else{if(m===d)throw new TypeError("Promise can't be resolved w/ itself");k(p.bind(m))}}catch(E){q(E)}}}function k(a){function b(a){return function(b){0<f++||a(b)}}var f=0,d=b(q);try{a(b(v),d)}catch(m){d(m)}}if(!(this instanceof z))throw Error("Promise must be called with `new`");if("function"!==typeof a)throw new TypeError("executor must be a function");
|
||||
var d=this,n=[],h=[],v=b(n,!0),q=b(h,!1),r=d._instance={resolvers:n,rejectors:h},l="function"===typeof setImmediate?setImmediate:setTimeout;k(a)};z.prototype.then=function(a,b){function k(a,b,k,p){b.push(function(b){if("function"!==typeof a)k(b);else try{n(a(b))}catch(f){h&&h(f)}});"function"===typeof d.retry&&p===d.state&&d.retry()}var d=this._instance,n,h,v=new z(function(a,b){n=a;h=b});k(a,d.resolvers,n,!0);k(b,d.rejectors,h,!1);return v};z.prototype["catch"]=function(a){return this.then(null,
|
||||
a)};z.resolve=function(a){return a instanceof z?a:new z(function(b){b(a)})};z.reject=function(a){return new z(function(b,k){k(a)})};z.all=function(a){return new z(function(b,k){var d=a.length,n=0,h=[];if(0===a.length)b([]);else for(var v=0;v<a.length;v++)(function(v){function r(a){n++;h[v]=a;n===d&&b(h)}null==a[v]||"object"!==typeof a[v]&&"function"!==typeof a[v]||"function"!==typeof a[v].then?r(a[v]):a[v].then(r,k)})(v)})};z.race=function(a){return new z(function(b,k){for(var d=0;d<a.length;d++)a[d].then(b,
|
||||
new function(){function m(a,b,k,d,l,h){return{tag:a,key:b,attrs:k,children:d,text:l,dom:h,domSize:void 0,state:{},events:void 0,instance:void 0,skip:!1}}function t(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===G[a]){for(var b,k,d=[],l={};b=N.exec(a);){var h=b[1],w=b[2];""===h&&""!==w?k=w:"#"===h?l.id=w:"."===h?d.push(w):"["===b[3][0]&&((h=b[6])&&(h=h.replace(/\\(["'])/g,"$1").replace(/\\\\/g,"\\")),
|
||||
"class"===b[4]?d.push(h):l[b[4]]=h||!0)}0<d.length&&(l.className=d.join(" "));G[a]=function(a,b){var d=!1,h,f,x=a.className||a["class"],n;for(n in l)a[n]=l[n];void 0!==x&&(void 0!==a["class"]&&(a["class"]=void 0,a.className=x),void 0!==l.className&&(a.className=l.className+" "+x));for(n in a)if("key"!==n){d=!0;break}b instanceof Array&&1==b.length&&null!=b[0]&&"#"===b[0].tag?f=b[0].children:h=b;return m(k||"div",a.key,d?a:void 0,h,f,void 0)}}var p;null!=arguments[1]&&("object"!==typeof arguments[1]||
|
||||
void 0!==arguments[1].tag||arguments[1]instanceof Array)?d=1:(p=arguments[1],d=2);if(arguments.length===d+1)b=arguments[d]instanceof Array?arguments[d]:[arguments[d]];else for(b=[];d<arguments.length;d++)b.push(arguments[d]);return"string"===typeof a?G[a](p||{},m.normalizeChildren(b)):m(a,p&&p.key,p||{},m.normalizeChildren(b),void 0,void 0)}m.normalize=function(a){return a instanceof Array?m("[",void 0,void 0,m.normalizeChildren(a),void 0,void 0):null!=a&&"object"!==typeof a?m("#",void 0,void 0,a,
|
||||
void 0,void 0):a};m.normalizeChildren=function(a){for(var b=0;b<a.length;b++)a[b]=m.normalize(a[b]);return a};var N=/(?:(^|#|\.)([^#\.\[\]]+))|(\[(.+?)(?:\s*=\s*("|'|)((?:\\["'\]]|.)*?)\5)?\])/g,G={};t.trust=function(a){null==a&&(a="");return m("<",void 0,void 0,a,void 0,void 0)};t.fragment=function(a,b){return m("[",a.key,a,m.normalizeChildren(b),void 0,void 0)};var z=function(a){function b(a,b){return function x(n){var q;try{if(!b||null==n||"object"!==typeof n&&"function"!==typeof n||"function"!==
|
||||
typeof(q=n.then))m(function(){b||0!==a.length||console.error("Possible unhandled promise rejection:",n);for(var d=0;d<a.length;d++)a[d](n);l.length=0;h.length=0;r.state=b;r.retry=function(){x(n)}});else{if(n===d)throw new TypeError("Promise can't be resolved w/ itself");k(q.bind(n))}}catch(E){p(E)}}}function k(a){function b(a){return function(b){0<f++||a(b)}}var f=0,d=b(p);try{a(b(w),d)}catch(n){d(n)}}if(!(this instanceof z))throw Error("Promise must be called with `new`");if("function"!==typeof a)throw new TypeError("executor must be a function");
|
||||
var d=this,l=[],h=[],w=b(l,!0),p=b(h,!1),r=d._instance={resolvers:l,rejectors:h},m="function"===typeof setImmediate?setImmediate:setTimeout;k(a)};z.prototype.then=function(a,b){function k(a,b,k,q){b.push(function(b){if("function"!==typeof a)k(b);else try{l(a(b))}catch(f){h&&h(f)}});"function"===typeof d.retry&&q===d.state&&d.retry()}var d=this._instance,l,h,w=new z(function(a,b){l=a;h=b});k(a,d.resolvers,l,!0);k(b,d.rejectors,h,!1);return w};z.prototype["catch"]=function(a){return this.then(null,
|
||||
a)};z.resolve=function(a){return a instanceof z?a:new z(function(b){b(a)})};z.reject=function(a){return new z(function(b,k){k(a)})};z.all=function(a){return new z(function(b,k){var d=a.length,l=0,h=[];if(0===a.length)b([]);else for(var w=0;w<a.length;w++)(function(w){function r(a){l++;h[w]=a;l===d&&b(h)}null==a[w]||"object"!==typeof a[w]&&"function"!==typeof a[w]||"function"!==typeof a[w].then?r(a[w]):a[w].then(r,k)})(w)})};z.race=function(a){return new z(function(b,k){for(var d=0;d<a.length;d++)a[d].then(b,
|
||||
k)})};"undefined"===typeof Promise&&("undefined"!==typeof window?window.Promise=z:"undefined"!==typeof global&&(global.Promise=z));var C=function(a){function b(a,d){if(d instanceof Array)for(var h=0;h<d.length;h++)b(a+"["+h+"]",d[h]);else if("[object Object]"===Object.prototype.toString.call(d))for(h in d)b(a+"["+h+"]",d[h]);else k.push(encodeURIComponent(a)+(null!=d&&""!==d?"="+encodeURIComponent(d):""))}if("[object Object]"!==Object.prototype.toString.call(a))return"";var k=[],d;for(d in a)b(d,
|
||||
a[d]);return k.join("&")},H=function(a,b){function k(){0===--p&&"function"===typeof w&&w()}function d(a){var f=a.then;a.then=function(){p++;var b=f.apply(a,arguments);b.then(k,function(a){k();throw a;});return d(b)};return a}function n(a,b){if(null==b)return a;for(var f=a.match(/:[^\/]+/gi)||[],d=0;d<f.length;d++){var h=f[d].slice(1);null!=b[h]&&(a=a.replace(f[d],b[h]),delete b[h])}return a}function h(a,b){var f=C(b);if(""!==f){var d=0>a.indexOf("?")?"?":"&";a+=d+f}return a}function v(a){try{return""!==
|
||||
a?JSON.parse(a):null}catch(x){throw Error(a);}}function q(a){return a.responseText}function r(a,b){if("function"===typeof a)if(b instanceof Array)for(var d=0;d<b.length;d++)b[d]=new a(b[d]);else return new a(b);return b}var l=0,p=0,w;return{request:function(f,k){return d(new b(function(b,d){if("string"===typeof f){var p=f;f=k||{};null==f.url&&(f.url=p)}null==f.method&&(f.method="GET");f.method=f.method.toUpperCase();p="boolean"===typeof f.useBody?f.useBody:"GET"!==f.method&&"TRACE"!==f.method;"function"!==
|
||||
typeof f.serialize&&(f.serialize="undefined"!==typeof FormData&&f.data instanceof FormData?function(a){return a}:JSON.stringify);"function"!==typeof f.deserialize&&(f.deserialize=v);"function"!==typeof f.extract&&(f.extract=q);f.url=n(f.url,f.data);p?f.data=f.serialize(f.data):f.url=h(f.url,f.data);var m=new a.XMLHttpRequest;m.open(f.method,f.url,"boolean"===typeof f.async?f.async:!0,"string"===typeof f.user?f.user:void 0,"string"===typeof f.password?f.password:void 0);f.serialize===JSON.stringify&&
|
||||
p&&m.setRequestHeader("Content-Type","application/json; charset=utf-8");f.deserialize===v&&m.setRequestHeader("Accept","application/json, text/*");f.withCredentials&&(m.withCredentials=f.withCredentials);"function"===typeof f.config&&(m=f.config(m,f)||m);m.onreadystatechange=function(){if(4===m.readyState)try{var a=f.extract!==q?f.extract(m,f):f.deserialize(f.extract(m,f));if(200<=m.status&&300>m.status||304===m.status)b(r(f.type,a));else{var h=Error(m.responseText),k;for(k in a)h[k]=a[k];d(h)}}catch(F){d(F)}};
|
||||
p&&null!=f.data?m.send(f.data):m.send()}))},jsonp:function(f){return d(new b(function(b,d){var m=f.callbackName||"_mithril_"+Math.round(1E16*Math.random())+"_"+l++,k=a.document.createElement("script");a[m]=function(d){k.parentNode.removeChild(k);b(r(f.type,d));delete a[m]};k.onerror=function(){k.parentNode.removeChild(k);d(Error("JSONP request failed"));delete a[m]};null==f.data&&(f.data={});f.url=n(f.url,f.data);f.data[f.callbackKey||"callback"]=m;k.src=h(f.url,f.data);a.document.documentElement.appendChild(k)}))},
|
||||
setCompletionCallback:function(a){w=a}}}(window,"undefined"!==typeof Promise?Promise:z),I=function(){var a=[];return{subscribe:a.push.bind(a),unsubscribe:function(b){b=a.indexOf(b);-1<b&&a.splice(b,1)},publish:function(){for(var b=0;b<a.length;b++)a[b].apply(this,arguments)}}}();H.setCompletionCallback(I.publish);var M=function(a){function b(c,g,a,b,d,f,h){for(;a<b;a++){var e=g[a];null!=e&&r(c,k(e,d,h),f)}}function k(c,g,a){var e=c.tag;null!=c.attrs&&t(c.attrs,c,g);if("string"===typeof e)switch(e){case "#":return c.dom=
|
||||
A.createTextNode(c.children);case "<":return d(c);case "[":var f=A.createDocumentFragment();null!=c.children&&(e=c.children,b(f,e,0,e.length,g,null,a));c.dom=f.firstChild;c.domSize=f.childNodes.length;return f;default:var h=c.tag;switch(c.tag){case "svg":a="http://www.w3.org/2000/svg";break;case "math":a="http://www.w3.org/1998/Math/MathML"}var p=(e=c.attrs)&&e.is,h=a?p?A.createElementNS(a,h,{is:p}):A.createElementNS(a,h):p?A.createElement(h,{is:p}):A.createElement(h);c.dom=h;if(null!=e)for(f in p=
|
||||
a,e)m(c,f,null,e[f],p);null!=c.attrs&&null!=c.attrs.contenteditable?z(c):(null!=c.text&&(""!==c.text?h.textContent=c.text:c.children=[l("#",void 0,void 0,c.text,void 0,void 0)]),null!=c.children&&(f=c.children,b(h,f,0,f.length,g,null,a),g=c.attrs,"select"===c.tag&&null!=g&&("value"in g&&m(c,"value",null,g.value,void 0),"selectedIndex"in g&&m(c,"selectedIndex",null,g.selectedIndex,void 0))));return h}else{c.state||(c.state={});O(c.state,c.tag);f=c.tag.view;if(null!=f.reentrantLock)c=F;else if(f.reentrantLock=
|
||||
!0,t(c.tag,c,g),c.instance=l.normalize(f.call(c.state,c)),f.reentrantLock=null,null!=c.instance){if(c.instance===c)throw Error("A view cannot return the vnode it received as arguments");g=k(c.instance,g,a);c.dom=c.instance.dom;c.domSize=null!=c.dom?c.instance.domSize:0;c=g}else c.domSize=0,c=F;return c}}function d(c){var g={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",g=A.createElement(g);
|
||||
g.innerHTML=c.children;c.dom=g.firstChild;c.domSize=g.childNodes.length;c=A.createDocumentFragment();for(var a;a=g.firstChild;)c.appendChild(a);return c}function n(c,a,e,f,d,m){if(a!==e&&(null!=a||null!=e))if(null==a)b(c,e,0,e.length,f,d,void 0);else if(null==e)p(a,0,a.length,e);else{var g;a:{if(null!=a.pool&&Math.abs(a.pool.length-e.length)<=Math.abs(a.length-e.length)&&(g=e[0]&&e[0].children&&e[0].children.length||0,Math.abs((a.pool[0]&&a.pool[0].children&&a.pool[0].children.length||0)-g)<=Math.abs((a[0]&&
|
||||
a[0].children&&a[0].children.length||0)-g))){g=!0;break a}g=!1}g&&(a=a.concat(a.pool));if(a.length===e.length&&null!=e[0]&&null==e[0].key)for(var u=0;u<a.length;u++)a[u]===e[u]||null==a[u]&&null==e[u]||(null==a[u]?r(c,k(e[u],f,m),q(a,u+1,d)):null==e[u]?p(a,u,u+1,e):h(c,a[u],e[u],f,q(a,u+1,d),g,m),g&&a[u].tag===e[u].tag&&r(c,v(a[u]),q(a,u+1,d)));else{for(var n=u=0,w=a.length-1,B=e.length-1,x;w>=u&&B>=n;){var y=a[u],l=e[n];if(y!==l||g)if(null!=y&&null!=l&&y.key===l.key)u++,n++,h(c,y,l,f,q(a,u,d),g,
|
||||
m),g&&y.tag===l.tag&&r(c,v(y),d);else if(y=a[w],y!==l||g)if(null!=y&&null!=l&&y.key===l.key)h(c,y,l,f,q(a,w+1,d),g,m),(g||n<B)&&r(c,v(y),q(a,u,d)),w--,n++;else break;else w--,n++;else u++,n++}for(;w>=u&&B>=n;){y=a[w];l=e[B];if(y!==l||g)if(null!=y&&null!=l&&y.key===l.key)h(c,y,l,f,q(a,w+1,d),g,m),g&&y.tag===l.tag&&r(c,v(y),d),null!=y.dom&&(d=y.dom),w--;else{if(!x){x=a;var y=w,D={},A;for(A=0;A<y;A++){var t=x[A];null!=t&&(t=t.key,null!=t&&(D[t]=A))}x=D}null!=l&&(y=x[l.key],null!=y?(D=a[y],h(c,D,l,f,
|
||||
q(a,w+1,d),g,m),r(c,v(D),d),a[y].skip=!0,null!=D.dom&&(d=D.dom)):(l=k(l,f,void 0),r(c,l,d),d=l))}else w--;B--;if(B<n)break}b(c,e,n,B+1,f,d,m);p(a,u,w+1,e)}}}function h(a,g,e,b,p,w,x){var c=g.tag;if(c===e.tag){e.state=g.state;e.events=g.events;var u;var B;null!=e.attrs&&"function"===typeof e.attrs.onbeforeupdate&&(u=e.attrs.onbeforeupdate.call(e.state,e,g));"string"!==typeof e.tag&&"function"===typeof e.tag.onbeforeupdate&&(B=e.tag.onbeforeupdate.call(e.state,e,g));void 0===u&&void 0===B||u||B?u=!1:
|
||||
(e.dom=g.dom,e.domSize=g.domSize,e.instance=g.instance,u=!0);if(!u)if(null!=e.attrs&&L(e.attrs,e,b,w),"string"===typeof c)switch(c){case "#":g.children.toString()!==e.children.toString()&&(g.dom.nodeValue=e.children);e.dom=g.dom;break;case "<":g.children!==e.children?(v(g),r(a,d(e),p)):(e.dom=g.dom,e.domSize=g.domSize);break;case "[":n(a,g.children,e.children,b,p,x);g=0;b=e.children;e.dom=null;if(null!=b){for(var q=0;q<b.length;q++)a=b[q],null!=a&&null!=a.dom&&(null==e.dom&&(e.dom=a.dom),g+=a.domSize||
|
||||
1);1!==g&&(e.domSize=g)}break;default:a=x;p=e.dom=g.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));w=g.attrs;x=e.attrs;c=a;if(null!=x)for(q in x)m(e,q,w&&w[q],x[q],c);if(null!=w)for(q in w)null!=x&&q in x||("className"===q&&(q="class"),"o"!==q[0]||"n"!==q[1]||K(q)?"key"!==q&&e.dom.removeAttribute(q):E(e,q,void 0));null!=e.attrs&&
|
||||
null!=e.attrs.contenteditable?z(e):null!=g.text&&null!=e.text&&""!==e.text?g.text.toString()!==e.text.toString()&&(g.dom.firstChild.nodeValue=e.text):(null!=g.text&&(g.children=[l("#",void 0,void 0,g.text,void 0,g.dom.firstChild)]),null!=e.text&&(e.children=[l("#",void 0,void 0,e.text,void 0,void 0)]),n(p,g.children,e.children,b,null,a))}else e.instance=l.normalize(e.tag.view.call(e.state,e)),L(e.tag,e,b,w),null!=e.instance?(null==g.instance?r(a,k(e.instance,b,x),p):h(a,g.instance,e.instance,b,p,
|
||||
w,x),e.dom=e.instance.dom,e.domSize=e.instance.domSize):null!=g.instance?(f(g.instance,null),e.dom=void 0,e.domSize=0):(e.dom=g.dom,e.domSize=g.domSize)}else f(g,null),r(a,k(e,b,x),p)}function v(a){var c=a.domSize;if(null!=c||null==a.dom){var e=A.createDocumentFragment();if(0<c){for(a=a.dom;--c;)e.appendChild(a.nextSibling);e.insertBefore(a,e.firstChild)}return e}return a.dom}function q(a,g,e){for(;g<a.length;g++)if(null!=a[g]&&null!=a[g].dom)return a[g].dom;return e}function r(a,g,e){e&&e.parentNode?
|
||||
a.insertBefore(g,e):a.appendChild(g)}function z(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!=c||null!=a.text)throw Error("Child node of a contenteditable must be trusted");}function p(a,g,e,b){for(;g<e;g++){var c=a[g];null!=c&&(c.skip?c.skip=!1:f(c,b))}}function w(a){var c=!1;return function(){c||(c=!0,a())}}function f(a,g){function c(){if(++d===b&&(x(a),a.dom)){var c=a.domSize||1;if(1<c)for(var e=a.dom;--c;){var f=
|
||||
e.nextSibling,h=f.parentNode;null!=h&&h.removeChild(f)}c=a.dom;e=c.parentNode;null!=e&&e.removeChild(c);if(c=null!=g&&null==a.domSize)c=a.attrs,c=!(null!=c&&(c.oncreate||c.onupdate||c.onbeforeremove||c.onremove));c&&"string"===typeof a.tag&&(g.pool?g.pool.push(a):g.pool=[a])}}var b=1,d=0;a.attrs&&a.attrs.onbeforeremove&&(b++,a.attrs.onbeforeremove.call(a.state,a,w(c)));"string"!==typeof a.tag&&a.tag.onbeforeremove&&(b++,a.tag.onbeforeremove.call(a.state,a,w(c)));c()}function x(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)x(a.instance);else if(a=a.children,a instanceof Array)for(var c=0;c<a.length;c++){var e=a[c];null!=e&&x(e)}}function m(a,g,e,b,d){var c=a.dom;if("key"!==g&&(e!==b||"value"===g||"checked"===g||"selectedIndex"===g||"selected"===g&&a.dom===A.activeElement||"object"===typeof b)&&"undefined"!==typeof b&&!K(g)){var f=g.indexOf(":");if(-1<f&&"xlink"===g.substr(0,f))c.setAttributeNS("http://www.w3.org/1999/xlink",
|
||||
g.slice(f+1),b);else if("o"===g[0]&&"n"===g[1]&&"function"===typeof b)E(a,g,b);else if("style"===g)if(a=e,a===b&&(c.style.cssText="",a=null),null==b)c.style.cssText="";else if("string"===typeof b)c.style.cssText=b;else{"string"===typeof a&&(c.style.cssText="");for(var h in b)c.style[h]=b[h];if(null!=a&&"string"!==typeof a)for(h in a)h in b||(c.style[h]="")}else g in c&&"href"!==g&&"list"!==g&&"form"!==g&&"width"!==g&&"height"!==g&&void 0===d?"input"===a.tag&&"value"===g&&a.dom.value===b&&a.dom===
|
||||
A.activeElement||"select"===a.tag&&"value"===g&&a.dom.value===b&&a.dom===A.activeElement||"option"===a.tag&&"value"===g&&a.dom.value===b||(c[g]=b):"boolean"===typeof b?b?c.setAttribute(g,""):c.removeAttribute(g):c.setAttribute("className"===g?"class":g,b)}}function K(a){return"oninit"===a||"oncreate"===a||"onupdate"===a||"onremove"===a||"onbeforeremove"===a||"onbeforeupdate"===a}function E(a,b,e){var c=a.dom,g=function(a){var b=e.call(c,a);"function"===typeof C&&C.call(c,a);return b};if(b in c)c[b]=
|
||||
"function"===typeof e?g:null;else{var d=b.slice(2);void 0===a.events&&(a.events={});null!=a.events[b]&&c.removeEventListener(d,a.events[b],!1);"function"===typeof e&&(a.events[b]=g,c.addEventListener(d,a.events[b],!1))}}function t(a,b,e){"function"===typeof a.oninit&&a.oninit.call(b.state,b);"function"===typeof a.oncreate&&e.push(a.oncreate.bind(b.state,b))}function L(a,b,e,d){d?t(a,b,e):"function"===typeof a.onupdate&&e.push(a.onupdate.bind(b.state,b))}function O(a,b){Object.keys(b).forEach(function(c){a[c]=
|
||||
b[c]})}var A=a.document,F=A.createDocumentFragment(),C;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=A.activeElement;null==a.vnodes&&(a.textContent="");b instanceof Array||(b=[b]);n(a,a.vnodes,l.normalizeChildren(b),c,null,void 0);a.vnodes=b;for(var f=0;f<c.length;f++)c[f]();A.activeElement!==d&&d.focus()},setEventCallback:function(a){return C=a}}}(window),P=function(a){var b=0,k=null,d="function"===typeof requestAnimationFrame?
|
||||
requestAnimationFrame:setTimeout;return function(n){var h=Date.now();!0===n||0===b||16<=h-b?(b=h,a()):null===k&&(k=d(function(){k=null;a();b=Date.now()},16-(h-b)))}},Q=function(a,b,k,d){d=P(d);null!=b&&b.setEventCallback(function(a){!1!==a.redraw&&k.publish()});null!=k&&(a.redraw&&k.unsubscribe(a.redraw),k.subscribe(d));return a.redraw=d};t.mount=function(a,b){return function(k,d){if(null===d)a.render(k,[]),b.unsubscribe(k.redraw),delete k.redraw;else{if(null==d.view)throw Error("m.mount(element, component) expects a component, not a vnode");
|
||||
Q(k,a,b,function(){a.render(k,l(d,void 0,void 0,void 0,void 0,void 0))})()}}}(M,I);var J=function(a){if(""===a||null==a)return{};"?"===a.charAt(0)&&(a=a.slice(1));a=a.split("&");for(var b={},k={},d=0;d<a.length;d++){var n=a[d].split("="),h=decodeURIComponent(n[0]),n=2===n.length?decodeURIComponent(n[1]):"";"true"===n?n=!0:"false"===n&&(n=!1);var l=h.split(/\]\[?|\[/),q=b;-1<h.indexOf("[")&&l.pop();for(var r=0;r<l.length;r++){var h=l[r],t=l[r+1],t=""==t||!isNaN(parseInt(t,10)),p=r===l.length-1;""===
|
||||
h&&(h=l.slice(0,r).join(),null==k[h]&&(k[h]=0),h=k[h]++);null==q[h]&&(q[h]=p?n:t?[]:{});q=q[h]}}return b},R=function(a){function b(b){var d=a.location[b].replace(/(?:%[a-f89][a-f0-9])+/gim,decodeURIComponent);"pathname"===b&&"/"!==d[0]&&(d="/"+d);return d}function k(a){return function(){null==t&&(t=q(function(){t=null;a()}))}}function d(a,b,d){var f=a.indexOf("?"),h=a.indexOf("#"),k=-1<f?f:-1<h?h:a.length;if(-1<f){var f=J(a.slice(f+1,-1<h?h:a.length)),p;for(p in f)b[p]=f[p]}if(-1<h)for(p in b=J(a.slice(h+
|
||||
1)),b)d[p]=b[p];return a.slice(0,k)}function n(){switch(r.charAt(0)){case "#":return b("hash").slice(r.length);case "?":return b("search").slice(r.length)+b("hash");default:return b("pathname").slice(r.length)+b("search")+b("hash")}}function h(b,h,f){var k={},m={};b=d(b,k,m);if(null!=h){for(var n in h)k[n]=h[n];b=b.replace(/:([^\/]+)/g,function(a,b){delete k[b];return h[b]})}(n=C(k))&&(b+="?"+n);(m=C(m))&&(b+="#"+m);l?(f&&f.replace?a.history.replaceState(null,null,r+b):a.history.pushState(null,null,
|
||||
r+b),a.onpopstate()):a.location.href=r+b}var l="function"===typeof a.history.pushState,q="function"===typeof setImmediate?setImmediate:setTimeout,r="#!",t;return{setPrefix:function(a){r=a},getPath:n,setPath:h,defineRoutes:function(b,h,f){function p(){var a=n(),k={},l=d(a,k,k),p;for(p in b){var q=new RegExp("^"+p.replace(/:[^\/]+?\.{3}/g,"(.*?)").replace(/:[^\/]+/g,"([^\\/]+)")+"/?$");if(q.test(l)){l.replace(q,function(){for(var d=p.match(/:[^\/]+/g)||[],f=[].slice.call(arguments,1,-2),m=0;m<d.length;m++)k[d[m].replace(/:|\./g,
|
||||
"")]=decodeURIComponent(f[m]);h(b[p],k,a,p)});return}}f(a,k)}l?a.onpopstate=k(p):"#"===r.charAt(0)&&(a.onhashchange=p);p();return p},link:function(a){a.dom.setAttribute("href",r+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(r)&&(a=a.slice(r.length)),h(a,void 0,void 0))}}}};t.route=function(a,b){function k(a){return a}var d=R(a),n,h,t,q,r,z={view:function(){return[t(l(h,null,q,void 0,
|
||||
void 0,void 0))]}},p=function(a,f,l){h="div";t=k;q=null;b(a,z);d.defineRoutes(l,function(b,d,f){var l="function"!==typeof b.view,m=k,p=n=function(k){p===n&&(n=null,h=null!=k?k:l?"div":b,t=m,q=d,r=f,a.redraw(!0))},v=function(){p()};l&&("function"===typeof b.render&&(m=b.render.bind(b)),"function"===typeof b.onmatch&&(v=b.onmatch));v.call(b,p,d,f)},function(){d.setPath(f,null,{replace:!0})})};p.link=d.link;p.prefix=d.setPrefix;p.set=d.setPath;p.get=function(){return r};return p}(window,t.mount);t.withAttr=
|
||||
function(a,b,k){return function(d){return b.call(k||this,a in d.currentTarget?d.currentTarget[a]:d.currentTarget.getAttribute(a))}};t.render=M.render;t.redraw=I.publish;t.request=H.request;t.jsonp=H.jsonp;t.parseQueryString=J;t.buildQueryString=C;t.version="1.0.0-rc.5";"undefined"!==typeof module?module.exports=t:window.m=t};
|
||||
a[d]);return k.join("&")},H=function(a,b){function k(){0===--q&&"function"===typeof u&&u()}function d(a){var f=a.then;a.then=function(){q++;var b=f.apply(a,arguments);b.then(k,function(a){k();throw a;});return d(b)};return a}function l(a,b){if(null==b)return a;for(var f=a.match(/:[^\/]+/gi)||[],d=0;d<f.length;d++){var h=f[d].slice(1);null!=b[h]&&(a=a.replace(f[d],b[h]),delete b[h])}return a}function h(a,b){var f=C(b);if(""!==f){var d=0>a.indexOf("?")?"?":"&";a+=d+f}return a}function w(a){try{return""!==
|
||||
a?JSON.parse(a):null}catch(x){throw Error(a);}}function p(a){return a.responseText}function r(a,b){if("function"===typeof a)if(b instanceof Array)for(var d=0;d<b.length;d++)b[d]=new a(b[d]);else return new a(b);return b}var m=0,q=0,u;return{request:function(f,k){return d(new b(function(b,d){if("string"===typeof f){var q=f;f=k||{};null==f.url&&(f.url=q)}null==f.method&&(f.method="GET");f.method=f.method.toUpperCase();q="boolean"===typeof f.useBody?f.useBody:"GET"!==f.method&&"TRACE"!==f.method;"function"!==
|
||||
typeof f.serialize&&(f.serialize="undefined"!==typeof FormData&&f.data instanceof FormData?function(a){return a}:JSON.stringify);"function"!==typeof f.deserialize&&(f.deserialize=w);"function"!==typeof f.extract&&(f.extract=p);f.url=l(f.url,f.data);q?f.data=f.serialize(f.data):f.url=h(f.url,f.data);var n=new a.XMLHttpRequest;n.open(f.method,f.url,"boolean"===typeof f.async?f.async:!0,"string"===typeof f.user?f.user:void 0,"string"===typeof f.password?f.password:void 0);f.serialize===JSON.stringify&&
|
||||
q&&n.setRequestHeader("Content-Type","application/json; charset=utf-8");f.deserialize===w&&n.setRequestHeader("Accept","application/json, text/*");f.withCredentials&&(n.withCredentials=f.withCredentials);"function"===typeof f.config&&(n=f.config(n,f)||n);n.onreadystatechange=function(){if(4===n.readyState)try{var a=f.extract!==p?f.extract(n,f):f.deserialize(f.extract(n,f));if(200<=n.status&&300>n.status||304===n.status)b(r(f.type,a));else{var h=Error(n.responseText),k;for(k in a)h[k]=a[k];d(h)}}catch(F){d(F)}};
|
||||
q&&null!=f.data?n.send(f.data):n.send()}))},jsonp:function(f){return d(new b(function(b,d){var n=f.callbackName||"_mithril_"+Math.round(1E16*Math.random())+"_"+m++,k=a.document.createElement("script");a[n]=function(d){k.parentNode.removeChild(k);b(r(f.type,d));delete a[n]};k.onerror=function(){k.parentNode.removeChild(k);d(Error("JSONP request failed"));delete a[n]};null==f.data&&(f.data={});f.url=l(f.url,f.data);f.data[f.callbackKey||"callback"]=n;k.src=h(f.url,f.data);a.document.documentElement.appendChild(k)}))},
|
||||
setCompletionCallback:function(a){u=a}}}(window,"undefined"!==typeof Promise?Promise:z),I=function(){var a=[];return{subscribe:a.push.bind(a),unsubscribe:function(b){b=a.indexOf(b);-1<b&&a.splice(b,1)},publish:function(){for(var b=0;b<a.length;b++)a[b].apply(this,arguments)}}}();H.setCompletionCallback(I.publish);var M=function(a){function b(c,g,a,b,d,f,h){for(;a<b;a++){var e=g[a];null!=e&&r(c,k(e,d,h),f)}}function k(c,g,a){var e=c.tag;null!=c.attrs&&t(c.attrs,c,g);if("string"===typeof e)switch(e){case "#":return c.dom=
|
||||
A.createTextNode(c.children);case "<":return d(c);case "[":var f=A.createDocumentFragment();null!=c.children&&(e=c.children,b(f,e,0,e.length,g,null,a));c.dom=f.firstChild;c.domSize=f.childNodes.length;return f;default:var h=c.tag;switch(c.tag){case "svg":a="http://www.w3.org/2000/svg";break;case "math":a="http://www.w3.org/1998/Math/MathML"}var q=(e=c.attrs)&&e.is,h=a?q?A.createElementNS(a,h,{is:q}):A.createElementNS(a,h):q?A.createElement(h,{is:q}):A.createElement(h);c.dom=h;if(null!=e)for(f in q=
|
||||
a,e)n(c,f,null,e[f],q);null!=c.attrs&&null!=c.attrs.contenteditable?z(c):(null!=c.text&&(""!==c.text?h.textContent=c.text:c.children=[m("#",void 0,void 0,c.text,void 0,void 0)]),null!=c.children&&(f=c.children,b(h,f,0,f.length,g,null,a),g=c.attrs,"select"===c.tag&&null!=g&&("value"in g&&n(c,"value",null,g.value,void 0),"selectedIndex"in g&&n(c,"selectedIndex",null,g.selectedIndex,void 0))));return h}else{c.state||(c.state={});O(c.state,c.tag);f=c.tag.view;if(null!=f.reentrantLock)c=F;else if(f.reentrantLock=
|
||||
!0,t(c.tag,c,g),c.instance=m.normalize(f.call(c.state,c)),f.reentrantLock=null,null!=c.instance){if(c.instance===c)throw Error("A view cannot return the vnode it received as arguments");g=k(c.instance,g,a);c.dom=c.instance.dom;c.domSize=null!=c.dom?c.instance.domSize:0;c=g}else c.domSize=0,c=F;return c}}function d(c){var g={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",g=A.createElement(g);
|
||||
g.innerHTML=c.children;c.dom=g.firstChild;c.domSize=g.childNodes.length;c=A.createDocumentFragment();for(var a;a=g.firstChild;)c.appendChild(a);return c}function l(c,a,e,f,d,n){if(a!==e&&(null!=a||null!=e))if(null==a)b(c,e,0,e.length,f,d,void 0);else if(null==e)q(a,0,a.length,e);else{var g;a:{if(null!=a.pool&&Math.abs(a.pool.length-e.length)<=Math.abs(a.length-e.length)&&(g=e[0]&&e[0].children&&e[0].children.length||0,Math.abs((a.pool[0]&&a.pool[0].children&&a.pool[0].children.length||0)-g)<=Math.abs((a[0]&&
|
||||
a[0].children&&a[0].children.length||0)-g))){g=!0;break a}g=!1}g&&(a=a.concat(a.pool));if(a.length===e.length&&null!=e[0]&&null==e[0].key)for(var v=0;v<a.length;v++)a[v]===e[v]||null==a[v]&&null==e[v]||(null==a[v]?r(c,k(e[v],f,n),p(a,v+1,d)):null==e[v]?q(a,v,v+1,e):h(c,a[v],e[v],f,p(a,v+1,d),g,n),g&&a[v].tag===e[v].tag&&r(c,w(a[v]),p(a,v+1,d)));else{for(var l=v=0,u=a.length-1,B=e.length-1,x;u>=v&&B>=l;){var y=a[v],m=e[l];if(y!==m||g)if(null==y)v++;else if(null==m)l++;else if(y.key===m.key)v++,l++,
|
||||
h(c,y,m,f,p(a,v,d),g,n),g&&y.tag===m.tag&&r(c,w(y),d);else if(y=a[u],y!==m||g)if(null==y)u--;else if(null==m)l++;else if(y.key===m.key)h(c,y,m,f,p(a,u+1,d),g,n),(g||l<B)&&r(c,w(y),p(a,v,d)),u--,l++;else break;else u--,l++;else v++,l++}for(;u>=v&&B>=l;){y=a[u];m=e[B];if(y!==m||g)if(null==y)u--;else{if(null!=m)if(y.key===m.key)h(c,y,m,f,p(a,u+1,d),g,n),g&&y.tag===m.tag&&r(c,w(y),d),null!=y.dom&&(d=y.dom),u--;else{if(!x){x=a;var y=u,D={},A;for(A=0;A<y;A++){var t=x[A];null!=t&&(t=t.key,null!=t&&(D[t]=
|
||||
A))}x=D}null!=m&&(y=x[m.key],null!=y?(D=a[y],h(c,D,m,f,p(a,u+1,d),g,n),r(c,w(D),d),a[y].skip=!0,null!=D.dom&&(d=D.dom)):(m=k(m,f,void 0),r(c,m,d),d=m))}B--}else u--,B--;if(B<l)break}b(c,e,l,B+1,f,d,n);q(a,v,u+1,e)}}}function h(a,g,e,b,q,u,x){var c=g.tag;if(c===e.tag){e.state=g.state;e.events=g.events;var v;var B;null!=e.attrs&&"function"===typeof e.attrs.onbeforeupdate&&(v=e.attrs.onbeforeupdate.call(e.state,e,g));"string"!==typeof e.tag&&"function"===typeof e.tag.onbeforeupdate&&(B=e.tag.onbeforeupdate.call(e.state,
|
||||
e,g));void 0===v&&void 0===B||v||B?v=!1:(e.dom=g.dom,e.domSize=g.domSize,e.instance=g.instance,v=!0);if(!v)if(null!=e.attrs&&L(e.attrs,e,b,u),"string"===typeof c)switch(c){case "#":g.children.toString()!==e.children.toString()&&(g.dom.nodeValue=e.children);e.dom=g.dom;break;case "<":g.children!==e.children?(w(g),r(a,d(e),q)):(e.dom=g.dom,e.domSize=g.domSize);break;case "[":l(a,g.children,e.children,b,q,x);g=0;b=e.children;e.dom=null;if(null!=b){for(var p=0;p<b.length;p++)a=b[p],null!=a&&null!=a.dom&&
|
||||
(null==e.dom&&(e.dom=a.dom),g+=a.domSize||1);1!==g&&(e.domSize=g)}break;default:a=x;q=e.dom=g.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));u=g.attrs;x=e.attrs;c=a;if(null!=x)for(p in x)n(e,p,u&&u[p],x[p],c);if(null!=u)for(p in u)null!=x&&p in x||("className"===p&&(p="class"),"o"!==p[0]||"n"!==p[1]||K(p)?"key"!==p&&e.dom.removeAttribute(p):
|
||||
E(e,p,void 0));null!=e.attrs&&null!=e.attrs.contenteditable?z(e):null!=g.text&&null!=e.text&&""!==e.text?g.text.toString()!==e.text.toString()&&(g.dom.firstChild.nodeValue=e.text):(null!=g.text&&(g.children=[m("#",void 0,void 0,g.text,void 0,g.dom.firstChild)]),null!=e.text&&(e.children=[m("#",void 0,void 0,e.text,void 0,void 0)]),l(q,g.children,e.children,b,null,a))}else e.instance=m.normalize(e.tag.view.call(e.state,e)),L(e.tag,e,b,u),null!=e.instance?(null==g.instance?r(a,k(e.instance,b,x),q):
|
||||
h(a,g.instance,e.instance,b,q,u,x),e.dom=e.instance.dom,e.domSize=e.instance.domSize):null!=g.instance?(f(g.instance,null),e.dom=void 0,e.domSize=0):(e.dom=g.dom,e.domSize=g.domSize)}else f(g,null),r(a,k(e,b,x),q)}function w(a){var c=a.domSize;if(null!=c||null==a.dom){var e=A.createDocumentFragment();if(0<c){for(a=a.dom;--c;)e.appendChild(a.nextSibling);e.insertBefore(a,e.firstChild)}return e}return a.dom}function p(a,g,e){for(;g<a.length;g++)if(null!=a[g]&&null!=a[g].dom)return a[g].dom;return e}
|
||||
function r(a,g,e){e&&e.parentNode?a.insertBefore(g,e):a.appendChild(g)}function z(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!=c||null!=a.text)throw Error("Child node of a contenteditable must be trusted");}function q(a,g,e,b){for(;g<e;g++){var c=a[g];null!=c&&(c.skip?c.skip=!1:f(c,b))}}function u(a){var c=!1;return function(){c||(c=!0,a())}}function f(a,g){function c(){if(++d===b&&(x(a),a.dom)){var c=a.domSize||
|
||||
1;if(1<c)for(var e=a.dom;--c;){var f=e.nextSibling,h=f.parentNode;null!=h&&h.removeChild(f)}c=a.dom;e=c.parentNode;null!=e&&e.removeChild(c);if(c=null!=g&&null==a.domSize)c=a.attrs,c=!(null!=c&&(c.oncreate||c.onupdate||c.onbeforeremove||c.onremove));c&&"string"===typeof a.tag&&(g.pool?g.pool.push(a):g.pool=[a])}}var b=1,d=0;a.attrs&&a.attrs.onbeforeremove&&(b++,a.attrs.onbeforeremove.call(a.state,a,u(c)));"string"!==typeof a.tag&&a.tag.onbeforeremove&&(b++,a.tag.onbeforeremove.call(a.state,a,u(c)));
|
||||
c()}function x(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)x(a.instance);else if(a=a.children,a instanceof Array)for(var c=0;c<a.length;c++){var e=a[c];null!=e&&x(e)}}function n(a,g,e,b,d){var c=a.dom;if("key"!==g&&(e!==b||"value"===g||"checked"===g||"selectedIndex"===g||"selected"===g&&a.dom===A.activeElement||"object"===typeof b)&&"undefined"!==typeof b&&!K(g)){var f=g.indexOf(":");if(-1<
|
||||
f&&"xlink"===g.substr(0,f))c.setAttributeNS("http://www.w3.org/1999/xlink",g.slice(f+1),b);else if("o"===g[0]&&"n"===g[1]&&"function"===typeof b)E(a,g,b);else if("style"===g)if(a=e,a===b&&(c.style.cssText="",a=null),null==b)c.style.cssText="";else if("string"===typeof b)c.style.cssText=b;else{"string"===typeof a&&(c.style.cssText="");for(var h in b)c.style[h]=b[h];if(null!=a&&"string"!==typeof a)for(h in a)h in b||(c.style[h]="")}else g in c&&"href"!==g&&"list"!==g&&"form"!==g&&"width"!==g&&"height"!==
|
||||
g&&void 0===d?"input"===a.tag&&"value"===g&&a.dom.value===b&&a.dom===A.activeElement||"select"===a.tag&&"value"===g&&a.dom.value===b&&a.dom===A.activeElement||"option"===a.tag&&"value"===g&&a.dom.value===b||(c[g]=b):"boolean"===typeof b?b?c.setAttribute(g,""):c.removeAttribute(g):c.setAttribute("className"===g?"class":g,b)}}function K(a){return"oninit"===a||"oncreate"===a||"onupdate"===a||"onremove"===a||"onbeforeremove"===a||"onbeforeupdate"===a}function E(a,b,e){var c=a.dom,g=function(a){var b=
|
||||
e.call(c,a);"function"===typeof C&&C.call(c,a);return b};if(b in c)c[b]="function"===typeof e?g:null;else{var d=b.slice(2);void 0===a.events&&(a.events={});null!=a.events[b]&&c.removeEventListener(d,a.events[b],!1);"function"===typeof e&&(a.events[b]=g,c.addEventListener(d,a.events[b],!1))}}function t(a,b,e){"function"===typeof a.oninit&&a.oninit.call(b.state,b);"function"===typeof a.oncreate&&e.push(a.oncreate.bind(b.state,b))}function L(a,b,e,d){d?t(a,b,e):"function"===typeof a.onupdate&&e.push(a.onupdate.bind(b.state,
|
||||
b))}function O(a,b){Object.keys(b).forEach(function(c){a[c]=b[c]})}var A=a.document,F=A.createDocumentFragment(),C;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=A.activeElement;null==a.vnodes&&(a.textContent="");b instanceof Array||(b=[b]);l(a,a.vnodes,m.normalizeChildren(b),c,null,void 0);a.vnodes=b;for(var f=0;f<c.length;f++)c[f]();A.activeElement!==d&&d.focus()},setEventCallback:function(a){return C=
|
||||
a}}}(window),P=function(a){var b=0,k=null,d="function"===typeof requestAnimationFrame?requestAnimationFrame:setTimeout;return function(l){var h=Date.now();!0===l||0===b||16<=h-b?(b=h,a()):null===k&&(k=d(function(){k=null;a();b=Date.now()},16-(h-b)))}},Q=function(a,b,k,d){d=P(d);null!=b&&b.setEventCallback(function(a){!1!==a.redraw&&k.publish()});null!=k&&(a.redraw&&k.unsubscribe(a.redraw),k.subscribe(d));return a.redraw=d};t.mount=function(a,b){return function(k,d){if(null===d)a.render(k,[]),b.unsubscribe(k.redraw),
|
||||
delete k.redraw;else{if(null==d.view)throw Error("m.mount(element, component) expects a component, not a vnode");Q(k,a,b,function(){a.render(k,m(d,void 0,void 0,void 0,void 0,void 0))})()}}}(M,I);var J=function(a){if(""===a||null==a)return{};"?"===a.charAt(0)&&(a=a.slice(1));a=a.split("&");for(var b={},k={},d=0;d<a.length;d++){var l=a[d].split("="),h=decodeURIComponent(l[0]),l=2===l.length?decodeURIComponent(l[1]):"";"true"===l?l=!0:"false"===l&&(l=!1);var m=h.split(/\]\[?|\[/),p=b;-1<h.indexOf("[")&&
|
||||
m.pop();for(var r=0;r<m.length;r++){var h=m[r],t=m[r+1],t=""==t||!isNaN(parseInt(t,10)),q=r===m.length-1;""===h&&(h=m.slice(0,r).join(),null==k[h]&&(k[h]=0),h=k[h]++);null==p[h]&&(p[h]=q?l:t?[]:{});p=p[h]}}return b},R=function(a){function b(b){var d=a.location[b].replace(/(?:%[a-f89][a-f0-9])+/gim,decodeURIComponent);"pathname"===b&&"/"!==d[0]&&(d="/"+d);return d}function k(a){return function(){null==t&&(t=p(function(){t=null;a()}))}}function d(a,b,d){var f=a.indexOf("?"),h=a.indexOf("#"),k=-1<f?
|
||||
f:-1<h?h:a.length;if(-1<f){var f=J(a.slice(f+1,-1<h?h:a.length)),l;for(l in f)b[l]=f[l]}if(-1<h)for(l in b=J(a.slice(h+1)),b)d[l]=b[l];return a.slice(0,k)}function l(){switch(r.charAt(0)){case "#":return b("hash").slice(r.length);case "?":return b("search").slice(r.length)+b("hash");default:return b("pathname").slice(r.length)+b("search")+b("hash")}}function h(b,h,f){var k={},n={};b=d(b,k,n);if(null!=h){for(var l in h)k[l]=h[l];b=b.replace(/:([^\/]+)/g,function(a,b){delete k[b];return h[b]})}(l=C(k))&&
|
||||
(b+="?"+l);(n=C(n))&&(b+="#"+n);m?(f&&f.replace?a.history.replaceState(null,null,r+b):a.history.pushState(null,null,r+b),a.onpopstate()):a.location.href=r+b}var m="function"===typeof a.history.pushState,p="function"===typeof setImmediate?setImmediate:setTimeout,r="#!",t;return{setPrefix:function(a){r=a},getPath:l,setPath:h,defineRoutes:function(b,h,f){function p(){var a=l(),k={},m=d(a,k,k),p;for(p in b){var u=new RegExp("^"+p.replace(/:[^\/]+?\.{3}/g,"(.*?)").replace(/:[^\/]+/g,"([^\\/]+)")+"/?$");
|
||||
if(u.test(m)){m.replace(u,function(){for(var d=p.match(/:[^\/]+/g)||[],f=[].slice.call(arguments,1,-2),l=0;l<d.length;l++)k[d[l].replace(/:|\./g,"")]=decodeURIComponent(f[l]);h(b[p],k,a,p)});return}}f(a,k)}m?a.onpopstate=k(p):"#"===r.charAt(0)&&(a.onhashchange=p);p();return p},link:function(a){a.dom.setAttribute("href",r+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(r)&&(a=a.slice(r.length)),
|
||||
h(a,void 0,void 0))}}}};t.route=function(a,b){function k(a){return a}var d=R(a),l,h,t,p,r,z={view:function(){return[t(m(h,null,p,void 0,void 0,void 0))]}},q=function(a,f,m){h="div";t=k;p=null;b(a,z);d.defineRoutes(m,function(b,d,f){var m="function"!==typeof b.view,n=k,q=l=function(k){q===l&&(l=null,h=null!=k?k:m?"div":b,t=n,p=d,r=f,a.redraw(!0))},u=function(){q()};m&&("function"===typeof b.render&&(n=b.render.bind(b)),"function"===typeof b.onmatch&&(u=b.onmatch));u.call(b,q,d,f)},function(){d.setPath(f,
|
||||
null,{replace:!0})})};q.link=d.link;q.prefix=d.setPrefix;q.set=d.setPath;q.get=function(){return r};return q}(window,t.mount);t.withAttr=function(a,b,k){return function(d){return b.call(k||this,a in d.currentTarget?d.currentTarget[a]:d.currentTarget.getAttribute(a))}};t.render=M.render;t.redraw=I.publish;t.request=H.request;t.jsonp=H.jsonp;t.parseQueryString=J;t.buildQueryString=C;t.version="1.0.0-rc.5";"undefined"!==typeof module?module.exports=t:window.m=t};
|
||||
|
|
@ -141,7 +141,9 @@ module.exports = function($window) {
|
|||
while (oldEnd >= oldStart && end >= start) {
|
||||
var o = old[oldStart], v = vnodes[start]
|
||||
if (o === v && !recycling) oldStart++, start++
|
||||
else if (o != null && v != null && o.key === v.key) {
|
||||
else if (o == null) oldStart++
|
||||
else if (v == null) start++
|
||||
else if (o.key === v.key) {
|
||||
oldStart++, start++
|
||||
updateNode(parent, o, v, hooks, getNextSibling(old, oldStart, nextSibling), recycling, ns)
|
||||
if (recycling && o.tag === v.tag) insertNode(parent, toFragment(o), nextSibling)
|
||||
|
|
@ -149,7 +151,9 @@ module.exports = function($window) {
|
|||
else {
|
||||
var o = old[oldEnd]
|
||||
if (o === v && !recycling) oldEnd--, start++
|
||||
else if (o != null && v != null && o.key === v.key) {
|
||||
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)
|
||||
if (recycling || start < end) insertNode(parent, toFragment(o), getNextSibling(old, oldStart, nextSibling))
|
||||
oldEnd--, start++
|
||||
|
|
@ -160,7 +164,9 @@ module.exports = function($window) {
|
|||
while (oldEnd >= oldStart && end >= start) {
|
||||
var o = old[oldEnd], v = vnodes[end]
|
||||
if (o === v && !recycling) oldEnd--, end--
|
||||
else if (o != null && v != null && o.key === v.key) {
|
||||
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)
|
||||
if (recycling && o.tag === v.tag) insertNode(parent, toFragment(o), nextSibling)
|
||||
if (o.dom != null) nextSibling = o.dom
|
||||
|
|
|
|||
|
|
@ -715,6 +715,22 @@ o.spec("updateNodes", function() {
|
|||
o(updated[2].dom.nodeName).equals("A")
|
||||
o(updated[2].dom).equals(root.childNodes[2])
|
||||
})
|
||||
o("change type, position and length", function() {
|
||||
var vnodes = {tag: "div", children: [
|
||||
undefined,
|
||||
{tag: "#", children: "a"}
|
||||
]}
|
||||
var updated = {tag: "div", children: [
|
||||
{tag: "[", children: [{tag: "#", children: "b"}]},
|
||||
undefined,
|
||||
undefined
|
||||
]}
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
o(root.firstChild.childNodes.length).equals(1)
|
||||
})
|
||||
o("removes then recreates then reverses children", function() {
|
||||
var vnodes = [{tag: "a", key: 1, children: [{tag: "i", key: 3}, {tag: "s", key: 4}]}, {tag: "b", key: 2}]
|
||||
var temp1 = []
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue