mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-19 00:20:33 +03:00
Favor function syntax over per-attribute function syntax
This commit is contained in:
@@ -13,26 +13,28 @@ import deepmerge from 'deepmerge'
|
||||
* @param {Function} opts.arrayMerge - how should arrays be merged?
|
||||
* @param {Object} [result={}] - result so far
|
||||
* @return {Object} result - final aggregated result
|
||||
* @return {Object} result.mergedOption - the actual merged options
|
||||
* @return {Object} result.deepestComponentWithMetaInfo - the deepest component in the heirarchy that has a `metaInfo` instance property
|
||||
*/
|
||||
export default function getComponentOption (opts, result = { mergedOption: {} }) {
|
||||
export default function getComponentOption (opts, result = {}) {
|
||||
const { component, option, deep, arrayMerge } = opts
|
||||
const { $options } = component
|
||||
|
||||
// only collect option data if it exists
|
||||
if (typeof $options[option] !== 'undefined' && $options[option] !== null) {
|
||||
const data = $options[option]
|
||||
let data = $options[option]
|
||||
|
||||
// if option is a function, replace it with it's result
|
||||
if (typeof data === 'function') {
|
||||
data = data.call(component)
|
||||
}
|
||||
|
||||
if (typeof data === 'object') {
|
||||
// merge with existing options
|
||||
result.mergedOption = deepmerge(result.mergedOption, data, {
|
||||
result = deepmerge(result, data, {
|
||||
clone: true,
|
||||
arrayMerge
|
||||
})
|
||||
result.deepestComponentWithMetaInfo = component
|
||||
} else {
|
||||
result.mergedOption = data
|
||||
result = data
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ export default function getMetaInfo (component) {
|
||||
}
|
||||
|
||||
// collect & aggregate all metaInfo $options
|
||||
const { mergedOption: info, deepestComponentWithMetaInfo } = getComponentOption({
|
||||
const info = getComponentOption({
|
||||
component,
|
||||
option: 'metaInfo',
|
||||
deep: true,
|
||||
@@ -71,15 +71,5 @@ export default function getMetaInfo (component) {
|
||||
info.base = Object.keys(info.base).length ? [info.base] : []
|
||||
}
|
||||
|
||||
const metaInfo = deepmerge(defaultInfo, info)
|
||||
|
||||
// inject component context into functions & call to normalize data
|
||||
Object.keys(metaInfo).forEach((key) => {
|
||||
const val = metaInfo[key]
|
||||
if (typeof val === 'function') {
|
||||
metaInfo[key] = val.call(deepestComponentWithMetaInfo)
|
||||
}
|
||||
})
|
||||
|
||||
return metaInfo
|
||||
return deepmerge(defaultInfo, info)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user