Replace x instanceof Array with Array.isArray(x)

This commit is contained in:
Barney Carroll 2016-11-24 09:21:27 +00:00
parent 106a9720d1
commit d82d337569
10 changed files with 32 additions and 34 deletions

View file

@ -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 <!-- size -->7.40 KB<!-- /size --> min+gzip
Despite the huge improvements in performance and modularity, the new codebase is smaller than v0.2.x, currently clocking at <!-- size -->7.41 KB<!-- /size --> 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

View file

@ -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]()

18
mithril.min.js vendored
View file

@ -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)}0<e.length&&(l.className=e.join(" "));H[a]=function(a,b){var e=!1,h,f,w=a.className||a["class"],n;for(n in l)a[n]=l[n];void 0!==w&&(void 0!==a["class"]&&(a["class"]=void 0,a.className=w),void 0!==l.className&&(a.className=l.className+" "+w));for(n in a)if("key"!==n){e=!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,e?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)?e=1:(p=arguments[1],e=2);if(arguments.length===e+1)b=arguments[e]instanceof Array?arguments[e]:[arguments[e]];else for(b=[];e<arguments.length;e++)b.push(arguments[e]);return"string"===typeof a?H[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 O=/(?:(^|#|\.)([^#\.\[\]]+))|(\[(.+?)(?:\s*=\s*("|'|)((?:\\["'\]]|.)*?)\5)?\])/g,H={};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 y=function(a){function b(a,b){return function w(n){var u;try{if(!b||null==n||"object"!==typeof n&&"function"!==typeof n||"function"!==
typeof(u=n.then))m(function(){b||0!==a.length||console.error("Possible unhandled promise rejection:",n);for(var e=0;e<a.length;e++)a[e](n);l.length=0;h.length=0;r.state=b;r.retry=function(){w(n)}});else{if(n===e)throw new TypeError("Promise can't be resolved w/ itself");k(u.bind(n))}}catch(F){p(F)}}}function k(a){function b(a){return function(b){0<f++||a(b)}}var f=0,e=b(p);try{a(b(v),e)}catch(n){e(n)}}if(!(this instanceof y))throw Error("Promise must be called with `new`");if("function"!==typeof a)throw new TypeError("executor must be a function");
"class"===b[4]?e.push(h):l[b[4]]=h||!0)}0<e.length&&(l.className=e.join(" "));H[a]=function(a,b){var e=!1,h,f,w=a.className||a["class"],n;for(n in l)a[n]=l[n];void 0!==w&&(void 0!==a["class"]&&(a["class"]=void 0,a.className=w),void 0!==l.className&&(a.className=l.className+" "+w));for(n in a)if("key"!==n){e=!0;break}Array.isArray(b)&&1==b.length&&null!=b[0]&&"#"===b[0].tag?f=b[0].children:h=b;return m(k||"div",a.key,e?a:void 0,h,f,void 0)}}var p;null==arguments[1]||"object"===typeof arguments[1]&&
void 0===arguments[1].tag&&!Array.isArray(arguments[1])?(p=arguments[1],e=2):e=1;if(arguments.length===e+1)b=Array.isArray(arguments[e])?arguments[e]:[arguments[e]];else for(b=[];e<arguments.length;e++)b.push(arguments[e]);return"string"===typeof a?H[a](p||{},m.normalizeChildren(b)):m(a,p&&p.key,p||{},m.normalizeChildren(b),void 0,void 0)}m.normalize=function(a){return Array.isArray(a)?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 O=/(?:(^|#|\.)([^#\.\[\]]+))|(\[(.+?)(?:\s*=\s*("|'|)((?:\\["'\]]|.)*?)\5)?\])/g,H={};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 y=function(a){function b(a,b){return function w(n){var u;try{if(!b||null==n||"object"!==typeof n&&"function"!==typeof n||"function"!==typeof(u=
n.then))m(function(){b||0!==a.length||console.error("Possible unhandled promise rejection:",n);for(var e=0;e<a.length;e++)a[e](n);l.length=0;h.length=0;r.state=b;r.retry=function(){w(n)}});else{if(n===e)throw new TypeError("Promise can't be resolved w/ itself");k(u.bind(n))}}catch(F){p(F)}}}function k(a){function b(a){return function(b){0<f++||a(b)}}var f=0,e=b(p);try{a(b(v),e)}catch(n){e(n)}}if(!(this instanceof y))throw Error("Promise must be called with `new`");if("function"!==typeof a)throw new TypeError("executor must be a function");
var e=this,l=[],h=[],v=b(l,!0),p=b(h,!1),r=e._instance={resolvers:l,rejectors:h},m="function"===typeof setImmediate?setImmediate:setTimeout;k(a)};y.prototype.then=function(a,b){function k(a,b,k,u){b.push(function(b){if("function"!==typeof a)k(b);else try{l(a(b))}catch(f){h&&h(f)}});"function"===typeof e.retry&&u===e.state&&e.retry()}var e=this._instance,l,h,v=new y(function(a,b){l=a;h=b});k(a,e.resolvers,l,!0);k(b,e.rejectors,h,!1);return v};y.prototype["catch"]=function(a){return this.then(null,
a)};y.resolve=function(a){return a instanceof y?a:new y(function(b){b(a)})};y.reject=function(a){return new y(function(b,k){k(a)})};y.all=function(a){return new y(function(b,k){var e=a.length,l=0,h=[];if(0===a.length)b([]);else for(var v=0;v<a.length;v++)(function(v){function r(a){l++;h[v]=a;l===e&&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)})};y.race=function(a){return new y(function(b,k){for(var e=0;e<a.length;e++)a[e].then(b,
k)})};"undefined"===typeof Promise&&("undefined"!==typeof window?window.Promise=y:"undefined"!==typeof global&&(global.Promise=y));var C=function(a){function b(a,e){if(e instanceof Array)for(var h=0;h<e.length;h++)b(a+"["+h+"]",e[h]);else if("[object Object]"===Object.prototype.toString.call(e))for(h in e)b(a+"["+h+"]",e[h]);else k.push(encodeURIComponent(a)+(null!=e&&""!==e?"="+encodeURIComponent(e):""))}if("[object Object]"!==Object.prototype.toString.call(a))return"";var k=[],e;for(e in a)b(e,
a[e]);return k.join("&")},I=function(a,b){function k(){0===--u&&"function"===typeof q&&q()}function e(a){var f=a.then;a.then=function(){u++;var b=f.apply(a,arguments);b.then(k,function(a){k();throw a;});return e(b)};return a}function l(a,b){if(null==b)return a;for(var f=a.match(/:[^\/]+/gi)||[],e=0;e<f.length;e++){var h=f[e].slice(1);null!=b[h]&&(a=a.replace(f[e],b[h]),delete b[h])}return a}function h(a,b){var f=C(b);if(""!==f){var e=0>a.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;e<b.length;e++)b[e]=new a(b[e]);else return new a(b);return b}var m=0,u=0,q;return{request:function(f,k){return e(new b(function(b,e){if("string"===typeof f){var u=f;f=k||{};null==f.url&&(f.url=u)}null==f.method&&(f.method="GET");f.method=f.method.toUpperCase();u="boolean"===typeof f.useBody?f.useBody:"GET"!==f.method&&"TRACE"!==f.method;"function"!==
k)})};"undefined"===typeof Promise&&("undefined"!==typeof window?window.Promise=y:"undefined"!==typeof global&&(global.Promise=y));var C=function(a){function b(a,e){if(Array.isArray(e))for(var h=0;h<e.length;h++)b(a+"["+h+"]",e[h]);else if("[object Object]"===Object.prototype.toString.call(e))for(h in e)b(a+"["+h+"]",e[h]);else k.push(encodeURIComponent(a)+(null!=e&&""!==e?"="+encodeURIComponent(e):""))}if("[object Object]"!==Object.prototype.toString.call(a))return"";var k=[],e;for(e in a)b(e,a[e]);
return k.join("&")},I=function(a,b){function k(){0===--u&&"function"===typeof q&&q()}function e(a){var f=a.then;a.then=function(){u++;var b=f.apply(a,arguments);b.then(k,function(a){k();throw a;});return e(b)};return a}function l(a,b){if(null==b)return a;for(var f=a.match(/:[^\/]+/gi)||[],e=0;e<f.length;e++){var h=f[e].slice(1);null!=b[h]&&(a=a.replace(f[e],b[h]),delete b[h])}return a}function h(a,b){var f=C(b);if(""!==f){var e=0>a.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;e<b.length;e++)b[e]=new a(b[e]);else return new a(b);return b}var m=0,u=0,q;return{request:function(f,k){return e(new b(function(b,e){if("string"===typeof f){var u=f;f=k||{};null==f.url&&(f.url=u)}null==f.method&&(f.method="GET");f.method=f.method.toUpperCase();u="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=p);f.url=l(f.url,f.data);u?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&&
u&&n.setRequestHeader("Content-Type","application/json; charset=utf-8");f.deserialize===v&&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];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<c){for(a=a.dom;--c;)d.appendChild(a.nextSibling);d.insertBefore(a,d.firstChild)}return d}return a.dom}function p(a,g,d){for(;g<a.length;g++)if(null!=a[g]&&null!=a[g].dom)return a[g].dom;return d}function r(a,g,d){d&&d.parentNode?
a.insertBefore(g,d):a.appendChild(g)}function y(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 u(a,g,d,b){for(;g<d;g++){var c=a[g];null!=c&&(c.skip?c.skip=!1:f(c,b))}}function q(a){var c=!1;return function(){c||(c=!0,a())}}function f(a,g){function c(){if(++e===b&&(w(a),a.dom)){var c=a.domSize||1;if(1<c)for(var d=a.dom;--c;){var f=
d.nextSibling,h=f.parentNode;null!=h&&h.removeChild(f)}c=a.dom;d=c.parentNode;null!=d&&d.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,e=0;a.attrs&&a.attrs.onbeforeremove&&(b++,a.attrs.onbeforeremove.call(a.state,a,q(c)));"string"!==typeof a.tag&&a.tag.onbeforeremove&&(b++,a.tag.onbeforeremove.call(a.state,a,q(c)));c()}function w(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)w(a.instance);else if(a=a.children,a instanceof Array)for(var c=0;c<a.length;c++){var d=a[c];null!=d&&w(d)}}function n(a,g,d,b,e){var c=a.dom;if("key"!==g&&(d!==b||"value"===g||"checked"===g||"selectedIndex"===g||"selected"===g&&a.dom===z.activeElement||"object"===typeof b)&&"undefined"!==typeof b&&!L(g)){var f=g.indexOf(":");if(-1<f&&"xlink"===g.substr(0,f))c.setAttributeNS("http://www.w3.org/1999/xlink",
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)w(a.instance);else if(a=a.children,Array.isArray(a))for(var c=0;c<a.length;c++){var d=a[c];null!=d&&w(d)}}function n(a,g,d,b,e){var c=a.dom;if("key"!==g&&(d!==b||"value"===g||"checked"===g||"selectedIndex"===g||"selected"===g&&a.dom===z.activeElement||"object"===typeof b)&&"undefined"!==typeof b&&!L(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)F(a,g,b);else if("style"===g)if(a=d,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===e?"input"===a.tag&&"value"===g&&a.dom.value===b&&a.dom===
z.activeElement||"select"===a.tag&&"value"===g&&a.dom.value===b&&a.dom===z.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 L(a){return"oninit"===a||"oncreate"===a||"onupdate"===a||"onremove"===a||"onbeforeremove"===a||"onbeforeupdate"===a}function F(a,b,d){var c=a.dom,g=function(a){var b=d.call(c,a);"function"===typeof C&&C.call(c,a);return b};if(b in c)c[b]=
"function"===typeof d?g:null;else{var e=b.slice(2);void 0===a.events&&(a.events={});null!=a.events[b]&&c.removeEventListener(e,a.events[b],!1);"function"===typeof d&&(a.events[b]=g,c.addEventListener(e,a.events[b],!1))}}function t(a,b,d){"function"===typeof a.oninit&&a.oninit.call(b.state,b);"function"===typeof a.oncreate&&d.push(a.oncreate.bind(b.state,b))}function M(a,b,d,e){e?t(a,b,d):"function"===typeof a.onupdate&&d.push(a.onupdate.bind(b.state,b))}function P(a,b){Object.keys(b).forEach(function(c){a[c]=
b[c]})}var z=a.document,G=z.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 d=[],c=z.activeElement;null==a.vnodes&&(a.textContent="");b instanceof Array||(b=[b]);l(a,a.vnodes,m.normalizeChildren(b),d,null,void 0);a.vnodes=b;for(var e=0;e<d.length;e++)d[e]();z.activeElement!==c&&c.focus()},setEventCallback:function(a){return C=a}}}(window),Q=function(a){var b=0,k=null,e="function"===typeof requestAnimationFrame?
b[c]})}var z=a.document,G=z.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 d=[],c=z.activeElement;null==a.vnodes&&(a.textContent="");Array.isArray(b)||(b=[b]);l(a,a.vnodes,m.normalizeChildren(b),d,null,void 0);a.vnodes=b;for(var e=0;e<d.length;e++)d[e]();z.activeElement!==c&&c.focus()},setEventCallback:function(a){return C=a}}}(window),Q=function(a){var b=0,k=null,e="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=e(function(){k=null;a();b=Date.now()},16-(h-b)))}},R=function(a,b,k,e){e=Q(e);null!=b&&b.setEventCallback(function(a){!1!==a.redraw&&k.publish()});null!=k&&(a.redraw&&k.unsubscribe(a.redraw),k.subscribe(e));return a.redraw=e};t.mount=function(a,b){return function(k,e){if(null===e)a.render(k,[]),b.unsubscribe(k.redraw),delete k.redraw;else{if(null==e.view)throw Error("m.mount(element, component) expects a component, not a vnode");
R(k,a,b,function(){a.render(k,m(e,void 0,void 0,void 0,void 0,void 0))})()}}}(N,J);var K=function(a){if(""===a||null==a)return{};"?"===a.charAt(0)&&(a=a.slice(1));a=a.split("&");for(var b={},k={},e=0;e<a.length;e++){var l=a[e].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)),u=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]=u?l:t?[]:{});p=p[h]}}return b},S=function(a){function b(b){var e=a.location[b].replace(/(?:%[a-f89][a-f0-9])+/gim,decodeURIComponent);"pathname"===b&&"/"!==e[0]&&(e="/"+e);return e}function k(a){return function(){null==t&&(t=p(function(){t=null;a()}))}}function e(a,b,e){var f=a.indexOf("?"),h=a.indexOf("#"),k=-1<f?f:-1<h?h:a.length;if(-1<f){var f=K(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=K(a.slice(h+

View file

@ -142,7 +142,7 @@ module.exports = new function init() {
}
return true
}
if (a.length === b.length && (a instanceof Array && b instanceof Array || aIsArgs && bIsArgs)) {
if (a.length === b.length && (Array.isArray(a) && Array.isArray(b) || aIsArgs && bIsArgs)) {
for (var i = 0; i < a.length; i++) {
if (!deepEqual(a[i], b[i])) return false
}
@ -185,7 +185,7 @@ module.exports = new function init() {
results.push(result)
}
function serialize(value) {
if (value === null || (typeof value === "object" && !(value instanceof Array)) || typeof value === "number") return String(value)
if (value === null || (typeof value === "object" && !Array.isArray(value)) || typeof value === "number") return String(value)
else if (typeof value === "function") return value.name || "<anonymous function>"
try {return JSON.stringify(value)} catch (e) {return String(value)}
}

View file

@ -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])
}

View file

@ -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 = []

View file

@ -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]()

View file

@ -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)

View file

@ -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
}

View file

@ -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])
}