diff --git a/src/compiler/codegen.js b/src/compiler/codegen.js index 501ce0aa..48294e4c 100644 --- a/src/compiler/codegen.js +++ b/src/compiler/codegen.js @@ -86,7 +86,7 @@ function genChildren (el) { if (!el.children.length) { return 'undefined' } - return '__flatten__([' + el.children.map(genNode).join(',') + '])' + return '[' + el.children.map(genNode).join(',') + ']' } function genNode (node) { diff --git a/src/instance/index.js b/src/instance/index.js index 8f7028df..e4643c22 100644 --- a/src/instance/index.js +++ b/src/instance/index.js @@ -43,23 +43,6 @@ export default class Component { : dynamic } - __flatten__ (arr) { - var res = [] - for (var i = 0, l = arr.length; i < l; i++) { - var e = arr[i] - if (Array.isArray(e)) { - for (var j = 0, k = e.length; j < k; j++) { - if (e[j]) { - res.push(e[j]) - } - } - } else if (e) { - res.push(e) - } - } - return res - } - _proxy (key) { if (!isReserved(key)) { // need to store ref to self here diff --git a/src/vdom/h.js b/src/vdom/h.js index 15af6e46..369d7e59 100644 --- a/src/vdom/h.js +++ b/src/vdom/h.js @@ -10,24 +10,29 @@ function addNS(data, children) { } } -export default function h (tag, b, c) { - var data = {}, children, text, i - if (arguments.length === 3) { - data = b - if (isArray(c)) { children = c } - else if (isPrimitive(c)) { text = c } - } else if (arguments.length === 2) { - if (isArray(b)) { children = b } - else if (isPrimitive(b)) { text = b } - else { data = b } - } +export default function h (tag, data, children) { if (isArray(children)) { - for (i = 0; i < children.length; ++i) { - if (isPrimitive(children[i])) children[i] = VNode(undefined, undefined, undefined, children[i]) + let _children = children + children = [] + for (let i = 0, l = _children.length; i < l; i++) { + let e = _children[i] + // flatten nested + if (isArray(e)) { + for (let j = 0, k = e.length; j < k; j++) { + if (e[j]) { + children.push(e[j]) + } + } + } else if (isPrimitive(e)) { + // convert primitive to vnode + children.push(VNode(undefined, undefined, undefined, e)) + } else if (e) { + children.push(e) + } } } if (tag === 'svg') { addNS(data, children) } - return VNode(tag, data, children, text, undefined) + return VNode(tag, data, children, undefined, undefined) } diff --git a/src/vdom/vnode.js b/src/vdom/vnode.js index 628bf873..ba7c9cca 100644 --- a/src/vdom/vnode.js +++ b/src/vdom/vnode.js @@ -1,4 +1,3 @@ export default function VNode (sel, data, children, text, elm) { - const key = data === undefined ? undefined : data.key - return { sel, data, children, text, elm, key } + return { sel, data, children, text, elm, key: data && data.key } }