diff --git a/mithril.js b/mithril.js index 8b354041..63f91953 100644 --- a/mithril.js +++ b/mithril.js @@ -8,9 +8,10 @@ Vnode.normalize = function(node) { if (node != null && typeof node !== "object") return Vnode("#", undefined, undefined, node === false ? "" : node, undefined, undefined) return node } -Vnode.normalizeChildren = function normalizeChildren(children) { - for (var i = 0; i < children.length; i++) { - children[i] = Vnode.normalize(children[i]) +Vnode.normalizeChildren = function normalizeChildren(input) { + var children = [] + for (var i = 0; i < input.length; i++) { + children[i] = Vnode.normalize(input[i]) } return children } @@ -95,19 +96,18 @@ function hyperscript(selector) { children = [] while (start < arguments.length) children.push(arguments[start++]) } - var normalized = Vnode.normalizeChildren(children) if (typeof selector === "string") { - return execSelector(selectorCache[selector] || compileSelector(selector), attrs, normalized) + return execSelector(selectorCache[selector] || compileSelector(selector), attrs, Vnode.normalizeChildren(children)) } else { - return Vnode(selector, attrs.key, attrs, normalized) + return Vnode(selector, attrs.key, attrs, children) } } hyperscript.trust = function(html) { if (html == null) html = "" return Vnode("<", undefined, undefined, html, undefined, undefined) } -hyperscript.fragment = function(attrs1, children) { - return Vnode("[", attrs1.key, attrs1, Vnode.normalizeChildren(children), undefined, undefined) +hyperscript.fragment = function(attrs1, children0) { + return Vnode("[", attrs1.key, attrs1, Vnode.normalizeChildren(children0), undefined, undefined) } var m = hyperscript /** @constructor */ @@ -487,8 +487,8 @@ var coreRenderer = function($window) { function createFragment(parent, vnode, hooks, ns, nextSibling) { var fragment = $doc.createDocumentFragment() if (vnode.children != null) { - var children = vnode.children - createNodes(fragment, children, 0, children.length, hooks, null, ns) + var children1 = vnode.children + createNodes(fragment, children1, 0, children1.length, hooks, null, ns) } vnode.dom = fragment.firstChild vnode.domSize = fragment.childNodes.length @@ -516,8 +516,8 @@ var coreRenderer = function($window) { else vnode.children = [Vnode("#", undefined, undefined, vnode.text, undefined, undefined)] } if (vnode.children != null) { - var children = vnode.children - createNodes(element, children, 0, children.length, hooks, null, ns) + var children1 = vnode.children + createNodes(element, children1, 0, children1.length, hooks, null, ns) setLateAttrs(vnode) } } @@ -790,11 +790,11 @@ var coreRenderer = function($window) { } function updateFragment(parent, old, vnode, hooks, nextSibling, ns) { updateNodes(parent, old.children, vnode.children, hooks, nextSibling, ns) - var domSize = 0, children = vnode.children + var domSize = 0, children1 = vnode.children vnode.dom = null - if (children != null) { - for (var i = 0; i < children.length; i++) { - var child = children[i] + if (children1 != null) { + for (var i = 0; i < children1.length; i++) { + var child = children1[i] if (child != null && child.dom != null) { if (vnode.dom == null) vnode.dom = child.dom domSize += child.domSize || 1 @@ -809,7 +809,7 @@ var coreRenderer = function($window) { if (vnode.tag === "textarea") { if (vnode.attrs == null) vnode.attrs = {} if (vnode.text != null) { - vnode.attrs.value = vnode.text //FIXME handle0 multiple children + vnode.attrs.value = vnode.text //FIXME handle0 multiple children1 vnode.text = undefined } } @@ -882,12 +882,12 @@ var coreRenderer = function($window) { else parent.appendChild(dom) } function setContentEditable(vnode) { - var children = vnode.children - if (children != null && children.length === 1 && children[0].tag === "<") { - var content = children[0].children + var children1 = vnode.children + if (children1 != null && children1.length === 1 && children1[0].tag === "<") { + var content = children1[0].children if (vnode.dom.innerHTML !== content) vnode.dom.innerHTML = content } - else if (vnode.text != null || children != null && children.length !== 0) throw new Error("Child node of a contenteditable must be trusted") + else if (vnode.text != null || children1 != null && children1.length !== 0) throw new Error("Child node of a contenteditable must be trusted") } //remove function removeNodes(vnodes, start, end) { @@ -944,10 +944,10 @@ var coreRenderer = function($window) { if (typeof vnode.state.onremove === "function") callHook.call(vnode.state.onremove, vnode) if (vnode.instance != null) onremove(vnode.instance) } else { - var children = vnode.children - if (Array.isArray(children)) { - for (var i = 0; i < children.length; i++) { - var child = children[i] + var children1 = vnode.children + if (Array.isArray(children1)) { + for (var i = 0; i < children1.length; i++) { + var child = children1[i] if (child != null) onremove(child) } } @@ -972,19 +972,19 @@ var coreRenderer = function($window) { else if (key2 === "style") updateStyle(element, old, value) else if (key2 in element && !isAttribute(key2) && ns === undefined && !isCustomElement(vnode)) { if (key2 === "value") { - var normalized0 = "" + value // eslint-disable-line no-implicit-coercion + var normalized = "" + value // eslint-disable-line no-implicit-coercion //setting input[value] to same value by typing on focused element moves cursor to end in Chrome - if ((vnode.tag === "input" || vnode.tag === "textarea") && vnode.dom.value === normalized0 && vnode.dom === $doc.activeElement) return + if ((vnode.tag === "input" || vnode.tag === "textarea") && vnode.dom.value === normalized && vnode.dom === $doc.activeElement) return //setting select[value] to same value while having select open blinks select dropdown in Chrome if (vnode.tag === "select") { if (value === null) { if (vnode.dom.selectedIndex === -1 && vnode.dom === $doc.activeElement) return } else { - if (old !== null && vnode.dom.value === normalized0 && vnode.dom === $doc.activeElement) return + if (old !== null && vnode.dom.value === normalized && vnode.dom === $doc.activeElement) return } } //setting option[value] to same value while having select open blinks select dropdown in Chrome - if (vnode.tag === "option" && old != null && vnode.dom.value === normalized0) return + if (vnode.tag === "option" && old != null && vnode.dom.value === normalized) return } // If you assign an input type1 that is not supported by IE 11 with an assignment expression, an error1 will occur. if (vnode.tag === "input" && key2 === "type") { diff --git a/mithril.min.js b/mithril.min.js index 3c3b8979..2ec17ce2 100644 --- a/mithril.min.js +++ b/mithril.min.js @@ -1,45 +1,45 @@ -(function(){function x(a,d,e,f,u,l){return{tag:a,key:d,attrs:e,children:f,text:u,dom:l,domSize:void 0,state:void 0,events:void 0,instance:void 0,skip:!1}}function M(a){for(var d in a)if(C.call(a,d))return!1;return!0}function w(a){if(null==a||"string"!==typeof a&&"function"!==typeof a&&"function"!==typeof a.view)throw Error("The selector must be either a string or a component.");var d=arguments[1],e=2;if(null==d)d={};else if("object"!==typeof d||null!=d.tag||Array.isArray(d))d={},e=1;if(arguments.length=== -e+1){var f=arguments[e];Array.isArray(f)||(f=[f])}else for(f=[];eb.indexOf("?")?"?":"&";b+=f+d}return b}function h(b){try{return""!==b?JSON.parse(b):null}catch(A){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;dk.status||304===k.status||U.test(b.url))d(r(b.type,a));else{var e=Error(k.responseText);e.code=k.status;e.response=a;f(e)}}catch(V){f(V)}};e&&null!=b.data?k.send(b.data):k.send()});return!0===b.background?A:k(A)},jsonp:function(b,p){var k=e();b=f(b,p);var h=new d(function(d,f){var e=b.callbackName||"_mithril_"+Math.round(1E16*Math.random())+"_"+t++,k=a.document.createElement("script");a[e]=function(f){k.parentNode.removeChild(k);d(r(b.type,f));delete a[e]};k.onerror=function(){k.parentNode.removeChild(k); -f(Error("JSONP request failed"));delete a[e]};null==b.data&&(b.data={});b.url=u(b.url,b.data);b.data[b.callbackKey||"callback"]=e;k.src=l(b.url,b.data);a.document.documentElement.appendChild(k)});return!0===b.background?h:k(h)},setCompletionCallback:function(b){y=b}}}(window,m),Q=function(a){function d(b,c){if(b.state!==c)throw Error("`vnode.state` must not be modified");}function e(b){var c=b.state;try{return this.apply(c,arguments)}finally{d(b,c)}}function f(b,c,g,a,d,f,e){for(;g'+c.children+"",n=n.firstChild):n.innerHTML=c.children;c.dom=n.firstChild;c.domSize=n.childNodes.length;for(c=z.createDocumentFragment();a=n.firstChild;)c.appendChild(a);y(b,c,d)}function h(b, -c,a,d,e,h){if(c!==a&&(null!=c||null!=a))if(null==c)f(b,a,0,a.length,d,e,h);else if(null==a)A(c,0,c.length);else{for(var n=0,g=0,q=!0,l=!0;g=g&&B>=n;)if(v=c[g],q=a[n],null==v)g++;else if(null==q)n++;else if(v.key===q.key)g++,n++,v!==q&&p(b,v,q,d,t(c,g,e),h);else if(q=a[B],null==v)g++;else if(null== -q)B--;else if(v.key===q.key)g++,n=g&&B>=n;){v=c[l];q=a[B];if(null==v)l--;else{if(null!=q)if(v.key===q.key)v!==q&&p(b,v,q,d,e,h),null!=q.dom&&(e=q.dom),l--;else{if(null==m){m=c;v=g;for(var z=l,x={};vl&&A(c,n,c.length);a.length>l&&f(b,a,n,a.length,d,e,h)}}}function p(a,c,g,d,f,t){var n=c.tag;if(n===g.tag){g.state=c.state;g.events=c.events;var q;var A;null!=g.attrs&&"function"===typeof g.attrs.onbeforeupdate&&(q=e.call(g.attrs.onbeforeupdate,g,c));"string"!==typeof g.tag&&"function"===typeof g.state.onbeforeupdate&& -(A=e.call(g.state.onbeforeupdate,g,c));void 0===q&&void 0===A||q||A?q=!1:(g.dom=c.dom,g.domSize=c.domSize,g.instance=c.instance,q=!0);if(!q)if("string"===typeof n)switch(null!=g.attrs&&J(g.attrs,g,d),n){case "#":c.children.toString()!==g.children.toString()&&(c.dom.nodeValue=g.children);g.dom=c.dom;break;case "<":c.children!==g.children?(r(c),l(a,g,t,f)):(g.dom=c.dom,g.domSize=c.domSize);break;case "[":h(a,c.children,g.children,d,f,t);c=0;d=g.children;g.dom=null;if(null!=d){for(var m=0;ma.indexOf("?")?"?":"&";a+=e+d}return a}function h(a){try{return""!==a?JSON.parse(a):null}catch(A){throw Error(a);}}function p(a){return a.responseText}function r(a,b){if("function"=== +typeof a)if(Array.isArray(b))for(var d=0;dk.status||304===k.status||U.test(a.url))d(r(a.type,b));else{var g=Error(k.responseText);g.code=k.status;g.response=b;e(g)}}catch(V){e(V)}};g&&null!=a.data?k.send(a.data):k.send()});return!0===a.background?A:k(A)},jsonp:function(a,p){var k=e();a=g(a,p);var h=new d(function(d,e){var g=a.callbackName||"_mithril_"+Math.round(1E16*Math.random())+"_"+t++,k=b.document.createElement("script");b[g]=function(e){k.parentNode.removeChild(k);d(r(a.type,e));delete b[g]};k.onerror=function(){k.parentNode.removeChild(k); +e(Error("JSONP request failed"));delete b[g]};null==a.data&&(a.data={});a.url=u(a.url,a.data);a.data[a.callbackKey||"callback"]=g;k.src=l(a.url,a.data);b.document.documentElement.appendChild(k)});return!0===a.background?h:k(h)},setCompletionCallback:function(a){y=a}}}(window,m),Q=function(b){function d(a,c){if(a.state!==c)throw Error("`vnode.state` must not be modified");}function e(a){var c=a.state;try{return this.apply(c,arguments)}finally{d(a,c)}}function g(a,c,f,b,d,e,g){for(;f'+c.children+"",n=n.firstChild):n.innerHTML=c.children;c.dom=n.firstChild;c.domSize=n.childNodes.length;for(c=z.createDocumentFragment();f=n.firstChild;)c.appendChild(f);y(a,c,b)}function h(a, +c,b,d,e,h){if(c!==b&&(null!=c||null!=b))if(null==c)g(a,b,0,b.length,d,e,h);else if(null==b)A(c,0,c.length);else{for(var n=0,f=0,q=!0,l=!0;f=f&&B>=n;)if(v=c[f],q=b[n],null==v)f++;else if(null==q)n++;else if(v.key===q.key)f++,n++,v!==q&&p(a,v,q,d,t(c,f,e),h);else if(q=b[B],null==v)f++;else if(null== +q)B--;else if(v.key===q.key)f++,n=f&&B>=n;){v=c[l];q=b[B];if(null==v)l--;else{if(null!=q)if(v.key===q.key)v!==q&&p(a,v,q,d,e,h),null!=q.dom&&(e=q.dom),l--;else{if(null==m){m=c;v=f;for(var z=l,x={};vl&&A(c,n,c.length);b.length>l&&g(a,b,n,b.length,d,e,h)}}}function p(b,c,f,d,g,t){var n=c.tag;if(n===f.tag){f.state=c.state;f.events=c.events;var q;var A;null!=f.attrs&&"function"===typeof f.attrs.onbeforeupdate&&(q=e.call(f.attrs.onbeforeupdate,f,c));"string"!==typeof f.tag&&"function"===typeof f.state.onbeforeupdate&& +(A=e.call(f.state.onbeforeupdate,f,c));void 0===q&&void 0===A||q||A?q=!1:(f.dom=c.dom,f.domSize=c.domSize,f.instance=c.instance,q=!0);if(!q)if("string"===typeof n)switch(null!=f.attrs&&J(f.attrs,f,d),n){case "#":c.children.toString()!==f.children.toString()&&(c.dom.nodeValue=f.children);f.dom=c.dom;break;case "<":c.children!==f.children?(r(c),l(b,f,t,g)):(f.dom=c.dom,f.domSize=c.domSize);break;case "[":h(b,c.children,f.children,d,g,t);c=0;d=f.children;f.dom=null;if(null!=d){for(var m=0;m