diff --git a/README.md b/README.md index f748cef7..71c22280 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,6 @@ There are over 4000 assertions in the test suite, and tests cover even difficult ## Modularity -Despite the huge improvements in performance and modularity, the new codebase is smaller than v0.2.x, currently clocking at 7.40 KB min+gzip +Despite the huge improvements in performance and modularity, the new codebase is smaller than v0.2.x, currently clocking at 7.41 KB min+gzip In addition, Mithril is now completely modular: you can import only the modules that you need and easily integrate 3rd party modules if you wish to use a different library for routing, ajax, and even rendering diff --git a/mithril.js b/mithril.js index 7fdbec3a..520055e5 100644 --- a/mithril.js +++ b/mithril.js @@ -4,7 +4,7 @@ function Vnode(tag, key, attrs0, children, text, dom) { return {tag: tag, key: key, attrs: attrs0, children: children, text: text, dom: dom, domSize: undefined, state: {}, events: undefined, instance: undefined, skip: false} } Vnode.normalize = function(node) { - if (node instanceof Array) return Vnode("[", undefined, undefined, Vnode.normalizeChildren(node), undefined, undefined) + if (Array.isArray(node)) return Vnode("[", undefined, undefined, Vnode.normalizeChildren(node), undefined, undefined) if (node != null && typeof node !== "object") return Vnode("#", undefined, undefined, node, undefined, undefined) return node } @@ -52,19 +52,19 @@ function hyperscript(selector) { break } } - if (children instanceof Array && children.length == 1 && children[0] != null && children[0].tag === "#") text = children[0].children + if (Array.isArray(children) && children.length == 1 && children[0] != null && children[0].tag === "#") text = children[0].children else childList = children return Vnode(tag || "div", attrs.key, hasAttrs ? attrs : undefined, childList, text, undefined) } } var attrs, children, childrenIndex - if (arguments[1] == null || typeof arguments[1] === "object" && arguments[1].tag === undefined && !(arguments[1] instanceof Array)) { + if (arguments[1] == null || typeof arguments[1] === "object" && arguments[1].tag === undefined && !Array.isArray(arguments[1])) { attrs = arguments[1] childrenIndex = 2 } else childrenIndex = 1 if (arguments.length === childrenIndex + 1) { - children = arguments[childrenIndex] instanceof Array ? arguments[childrenIndex] : [arguments[childrenIndex]] + children = Array.isArray(arguments[childrenIndex]) ? arguments[childrenIndex] : [arguments[childrenIndex]] } else { children = [] @@ -187,7 +187,7 @@ var buildQueryString = function(object) { } return args.join("&") function destructure(key0, value) { - if (value instanceof Array) { + if (Array.isArray(value)) { for (var i = 0; i < value.length; i++) { destructure(key0 + "[" + i + "]", value[i]) } @@ -219,7 +219,6 @@ var _8 = function($window, Promise) { } return promise0 } - function request(args, extra) { return finalize(new Promise(function(resolve, reject) { if (typeof args === "string") { @@ -316,7 +315,7 @@ var _8 = function($window, Promise) { function extract(xhr) {return xhr.responseText} function cast(type0, data) { if (typeof type0 === "function") { - if (data instanceof Array) { + if (Array.isArray(data)) { for (var i = 0; i < data.length; i++) { data[i] = new type0(data[i]) } @@ -467,7 +466,6 @@ var _13 = function($window) { else { var recycling = isRecyclable(old, vnodes) if (recycling) 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] @@ -739,7 +737,7 @@ var _13 = function($window) { if (vnode.instance != null) onremove(vnode.instance) else { var children = vnode.children - if (children instanceof Array) { + if (Array.isArray(children)) { for (var i = 0; i < children.length; i++) { var child = children[i] if (child != null) onremove(child) @@ -880,7 +878,7 @@ var _13 = function($window) { var active = $doc.activeElement // First time rendering into a node clears it out if (dom.vnodes == null) dom.textContent = "" - if (!(vnodes instanceof Array)) vnodes = [vnodes] + if (!Array.isArray(vnodes)) vnodes = [vnodes] updateNodes(dom, dom.vnodes, Vnode.normalizeChildren(vnodes), hooks, null, undefined) dom.vnodes = vnodes for (var i = 0; i < hooks.length; i++) hooks[i]() diff --git a/mithril.min.js b/mithril.min.js index 41590c4a..5a8f0d69 100644 --- a/mithril.min.js +++ b/mithril.min.js @@ -1,13 +1,13 @@ new function(){function m(a,b,k,e,l,h){return{tag:a,key:b,attrs:k,children:e,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===H[a]){for(var b,k,e=[],l={};b=O.exec(a);){var h=b[1],v=b[2];""===h&&""!==v?k=v:"#"===h?l.id=v:"."===h?e.push(v):"["===b[3][0]&&((h=b[6])&&(h=h.replace(/\\(["'])/g,"$1").replace(/\\\\/g,"\\")), -"class"===b[4]?e.push(h):l[b[4]]=h||!0)}0a.indexOf("?")?"?":"&";a+=e+f}return a}function v(a){try{return""!== -a?JSON.parse(a):null}catch(w){throw Error(a);}}function p(a){return a.responseText}function r(a,b){if("function"===typeof a)if(b instanceof Array)for(var e=0;ea.indexOf("?")?"?":"&";a+=e+f}return a}function v(a){try{return""!== +a?JSON.parse(a):null}catch(w){throw Error(a);}}function p(a){return a.responseText}function r(a,b){if("function"===typeof a)if(Array.isArray(b))for(var e=0;en.status||304===n.status)b(r(f.type,a));else{var h=Error(n.responseText),k;for(k in a)h[k]=a[k];e(h)}}catch(G){e(G)}}; u&&null!=f.data?n.send(f.data):n.send()}))},jsonp:function(f){return e(new b(function(b,e){var n=f.callbackName||"_mithril_"+Math.round(1E16*Math.random())+"_"+m++,k=a.document.createElement("script");a[n]=function(e){k.parentNode.removeChild(k);b(r(f.type,e));delete a[n]};k.onerror=function(){k.parentNode.removeChild(k);e(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)}))}, @@ -25,11 +25,11 @@ d.attrs&&null!=d.attrs.contenteditable?y(d):null!=g.text&&null!=d.text&&""!==d.t b,u,q,w),d.dom=d.instance.dom,d.domSize=d.instance.domSize):null!=g.instance?(f(g.instance,null),d.dom=void 0,d.domSize=0):(d.dom=g.dom,d.domSize=g.domSize)}else f(g,null),r(a,k(d,b,w),u)}function v(a){var c=a.domSize;if(null!=c||null==a.dom){var d=z.createDocumentFragment();if(0" try {return JSON.stringify(value)} catch (e) {return String(value)} } diff --git a/querystring/build.js b/querystring/build.js index 3bea081f..55474392 100644 --- a/querystring/build.js +++ b/querystring/build.js @@ -10,7 +10,7 @@ module.exports = function(object) { return args.join("&") function destructure(key, value) { - if (value instanceof Array) { + if (Array.isArray(value)) { for (var i = 0; i < value.length; i++) { destructure(key + "[" + i + "]", value[i]) } diff --git a/render/hyperscript.js b/render/hyperscript.js index 28ce0d35..a2cf7332 100644 --- a/render/hyperscript.js +++ b/render/hyperscript.js @@ -41,20 +41,20 @@ function hyperscript(selector) { break } } - if (children instanceof Array && children.length == 1 && children[0] != null && children[0].tag === "#") text = children[0].children + if (Array.isArray(children) && children.length == 1 && children[0] != null && children[0].tag === "#") text = children[0].children else childList = children return Vnode(tag || "div", attrs.key, hasAttrs ? attrs : undefined, childList, text, undefined) } } var attrs, children, childrenIndex - if (arguments[1] == null || typeof arguments[1] === "object" && arguments[1].tag === undefined && !(arguments[1] instanceof Array)) { + if (arguments[1] == null || typeof arguments[1] === "object" && arguments[1].tag === undefined && !Array.isArray(arguments[1])) { attrs = arguments[1] childrenIndex = 2 } else childrenIndex = 1 if (arguments.length === childrenIndex + 1) { - children = arguments[childrenIndex] instanceof Array ? arguments[childrenIndex] : [arguments[childrenIndex]] + children = Array.isArray(arguments[childrenIndex]) ? arguments[childrenIndex] : [arguments[childrenIndex]] } else { children = [] diff --git a/render/render.js b/render/render.js index 909477a2..a851c91f 100644 --- a/render/render.js +++ b/render/render.js @@ -135,7 +135,7 @@ module.exports = function($window) { else { var recycling = isRecyclable(old, vnodes) if (recycling) 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] @@ -410,7 +410,7 @@ module.exports = function($window) { if (vnode.instance != null) onremove(vnode.instance) else { var children = vnode.children - if (children instanceof Array) { + if (Array.isArray(children)) { for (var i = 0; i < children.length; i++) { var child = children[i] if (child != null) onremove(child) @@ -559,7 +559,7 @@ module.exports = function($window) { // First time rendering into a node clears it out if (dom.vnodes == null) dom.textContent = "" - if (!(vnodes instanceof Array)) vnodes = [vnodes] + if (!Array.isArray(vnodes)) vnodes = [vnodes] updateNodes(dom, dom.vnodes, Vnode.normalizeChildren(vnodes), hooks, null, undefined) dom.vnodes = vnodes for (var i = 0; i < hooks.length; i++) hooks[i]() diff --git a/render/tests/test-fragment.js b/render/tests/test-fragment.js index f0403bbc..b10fc850 100644 --- a/render/tests/test-fragment.js +++ b/render/tests/test-fragment.js @@ -11,7 +11,7 @@ o.spec("fragment", function() { o(frag.tag).equals("[") - o(frag.children instanceof Array).equals(true) + o(Array.isArray(frag.children)).equals(true) o(frag.children.length).equals(1) o(frag.children[0]).equals(child) @@ -24,7 +24,7 @@ o.spec("fragment", function() { var frag = fragment(attrs, []) o(frag.tag).equals("[") - o(frag.children instanceof Array).equals(true) + o(Array.isArray(frag.children)).equals(true) o(frag.children.length).equals(0) o(frag.attrs).equals(attrs) diff --git a/render/vnode.js b/render/vnode.js index 0c52d53d..99877e4e 100644 --- a/render/vnode.js +++ b/render/vnode.js @@ -2,7 +2,7 @@ function Vnode(tag, key, attrs, children, text, dom) { return {tag: tag, key: key, attrs: attrs, children: children, text: text, dom: dom, domSize: undefined, state: {}, events: undefined, instance: undefined, skip: false} } Vnode.normalize = function(node) { - if (node instanceof Array) return Vnode("[", undefined, undefined, Vnode.normalizeChildren(node), undefined, undefined) + if (Array.isArray(node)) return Vnode("[", undefined, undefined, Vnode.normalizeChildren(node), undefined, undefined) if (node != null && typeof node !== "object") return Vnode("#", undefined, undefined, node, undefined, undefined) return node } diff --git a/request/request.js b/request/request.js index a005f240..91ea17a3 100644 --- a/request/request.js +++ b/request/request.js @@ -23,7 +23,7 @@ module.exports = function($window, Promise) { } return promise } - + function request(args, extra) { return finalize(new Promise(function(resolve, reject) { if (typeof args === "string") { @@ -136,7 +136,7 @@ module.exports = function($window, Promise) { function cast(type, data) { if (typeof type === "function") { - if (data instanceof Array) { + if (Array.isArray(data)) { for (var i = 0; i < data.length; i++) { data[i] = new type(data[i]) }