2
0
mirror of https://github.com/tenrok/vue-meta.git synced 2026-05-26 19:14:04 +03:00

improve tests for getComponentOption

This commit is contained in:
Declan de Wet
2016-11-05 07:33:13 +02:00
parent 6a1f1c280d
commit 8aec696ffa
2 changed files with 29 additions and 14 deletions
+8 -14
View File
@@ -24,14 +24,10 @@ export default function getComponentOption (opts, result = {}) {
if (typeof data === 'object') {
// bind context of option methods (if any) to this component
for (const key in data) {
if (data.hasOwnProperty(key)) {
const value = data[key]
if (typeof value === 'function') {
data[key] = value.bind(component)
}
}
}
Object.keys(data).forEach((key) => {
const value = data[key]
data[key] = typeof value === 'function' ? value.bind(component) : value
})
// merge with existing options
result = deepmerge(result, data, {
@@ -40,17 +36,15 @@ export default function getComponentOption (opts, result = {}) {
})
// collect & aggregate child options if deep = true
if (deep) {
const { $children } = component
for (let i = 0, len = $children.length; i < len; i++) {
const component = $children[i]
if (deep && component.$children.length) {
component.$children.forEach((childComponent) => {
result = getComponentOption({
component: childComponent,
option,
deep,
component,
arrayMerge
}, result)
}
})
}
return result