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 516b0c7f..47c65aae 100644 --- a/render/render.js +++ b/render/render.js @@ -417,7 +417,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) @@ -566,7 +566,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/tests/test-onbeforeremove.js b/render/tests/test-onbeforeremove.js index 82a859d0..c9af4894 100644 --- a/render/tests/test-onbeforeremove.js +++ b/render/tests/test-onbeforeremove.js @@ -158,14 +158,14 @@ o.spec("onbeforeremove", function() { render(root, vnodes) render(root, updated) - + o(root.childNodes.length).equals(2) o(root.firstChild.firstChild.nodeValue).equals("1") - + callAsync(function() { o(root.childNodes.length).equals(1) o(root.firstChild.firstChild.nodeValue).equals("2") - + done() }) }) @@ -184,4 +184,25 @@ o.spec("onbeforeremove", function() { done() }) }) + o("awaits promise resolution before removing the node", function(done) { + var view = o.spy() + var onremove = o.spy() + var onbeforeremove = function(){return new Promise(function(resolve){callAsync(resolve)})} + var component = { + onbeforeremove: onbeforeremove, + onremove: onremove, + view: view, + } + render(root, [{tag: component}]) + render(root, []) + + callAsync(function(){ + o(onremove.callCount).equals(0) + + callAsync(function() { + o(onremove.callCount).equals(1) + done() + }) + }) + }) }) 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 11e2e956..123ae1e7 100644 --- a/request/request.js +++ b/request/request.js @@ -152,7 +152,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]) }