Merge pull request #1423 from barneycarroll/array-isArray
Replace x instanceof Array with Array.isArray(x)
This commit is contained in:
commit
f149003d03
7 changed files with 34 additions and 13 deletions
|
|
@ -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])
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 = []
|
||||
|
|
|
|||
|
|
@ -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]()
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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])
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue