mirror of
https://github.com/vuejs/vue.git
synced 2024-11-21 20:28:54 +00:00
move flatten into vdom implementation
This commit is contained in:
parent
c1a8267c94
commit
69e94eb453
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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 }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user