mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-05 05:32:25 +03:00
fix: dont use object.assign/spread
so we dont need a polyfill
This commit is contained in:
committed by
Alexander Lichter
parent
93f021b757
commit
d717dbf4e1
+1
-1
@@ -1,6 +1,6 @@
|
||||
import { version } from '../package.json'
|
||||
import createMixin from './shared/mixin'
|
||||
import setOptions from './shared/options'
|
||||
import { setOptions } from './shared/options'
|
||||
import { isUndefined } from './utils/is-type'
|
||||
import $meta from './client/$meta'
|
||||
import { hasMetaInfo } from './shared/meta-helpers'
|
||||
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
import { getOptions } from '../shared/options'
|
||||
import { pause, resume } from '../shared/pausing'
|
||||
import refresh from './refresh'
|
||||
|
||||
@@ -12,7 +13,7 @@ export default function _$meta(options = {}) {
|
||||
*/
|
||||
return function $meta() {
|
||||
return {
|
||||
getOptions: () => Object.freeze({ ...options }),
|
||||
getOptions: () => getOptions(options),
|
||||
refresh: _refresh.bind(this),
|
||||
inject,
|
||||
pause: pause.bind(this),
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
import { version } from '../package.json'
|
||||
import createMixin from './shared/mixin'
|
||||
import setOptions from './shared/options'
|
||||
import { setOptions } from './shared/options'
|
||||
import $meta from './server/$meta'
|
||||
import { hasMetaInfo } from './shared/meta-helpers'
|
||||
|
||||
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
import refresh from '../client/refresh'
|
||||
import { getOptions } from '../shared/options'
|
||||
import { pause, resume } from '../shared/pausing'
|
||||
import refresh from '../client/refresh'
|
||||
import inject from './inject'
|
||||
|
||||
export default function _$meta(options = {}) {
|
||||
@@ -13,7 +14,7 @@ export default function _$meta(options = {}) {
|
||||
*/
|
||||
return function $meta() {
|
||||
return {
|
||||
getOptions: () => Object.freeze({ ...options }),
|
||||
getOptions: () => getOptions(options),
|
||||
refresh: _refresh.bind(this),
|
||||
inject: _inject.bind(this),
|
||||
pause: pause.bind(this),
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { isFunction, isObject } from '../utils/is-type'
|
||||
import { findIndex } from '../utils/array'
|
||||
import { merge } from './merge'
|
||||
import { applyTemplate } from './template'
|
||||
import { inMetaInfoBranch } from './meta-helpers'
|
||||
@@ -17,8 +18,8 @@ import { inMetaInfoBranch } from './meta-helpers'
|
||||
* @param {Object} [result={}] - result so far
|
||||
* @return {Object} result - final aggregated result
|
||||
*/
|
||||
export default function getComponentOption(options = {}, result = {}) {
|
||||
const { component, keyName, metaTemplateKeyName, tagIDKeyName } = options
|
||||
export default function getComponentOption(options = {}, component, result = {}) {
|
||||
const { keyName, metaTemplateKeyName, tagIDKeyName } = options
|
||||
const { $options, $children } = component
|
||||
|
||||
if (component._inactive) {
|
||||
@@ -52,10 +53,7 @@ export default function getComponentOption(options = {}, result = {}) {
|
||||
return
|
||||
}
|
||||
|
||||
result = getComponentOption({
|
||||
...options,
|
||||
component: childComponent
|
||||
}, result)
|
||||
result = getComponentOption(options, childComponent, result)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -69,7 +67,7 @@ export default function getComponentOption(options = {}, result = {}) {
|
||||
// keep meta item if it doesnt has a vmid
|
||||
!metaItem.hasOwnProperty(tagIDKeyName) ||
|
||||
// or if it's the first item in the array with this vmid
|
||||
index === arr.findIndex(item => item[tagIDKeyName] === metaItem[tagIDKeyName])
|
||||
index === findIndex(arr, item => item[tagIDKeyName] === metaItem[tagIDKeyName])
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { isObject } from '../utils/is-type'
|
||||
import { defaultOptions } from './constants'
|
||||
|
||||
export default function setOptions(options) {
|
||||
export function setOptions(options) {
|
||||
// combine options
|
||||
options = isObject(options) ? options : {}
|
||||
|
||||
@@ -13,3 +13,11 @@ export default function setOptions(options) {
|
||||
|
||||
return options
|
||||
}
|
||||
|
||||
export function getOptions(options) {
|
||||
const optionsCopy = {}
|
||||
for (const key in options) {
|
||||
optionsCopy[key] = options[key]
|
||||
}
|
||||
return optionsCopy
|
||||
}
|
||||
|
||||
@@ -9,13 +9,13 @@ describe('getComponentOption', () => {
|
||||
|
||||
test('returns an empty object when no matching options are found', () => {
|
||||
const component = new Vue()
|
||||
const mergedOption = getComponentOption({ component, keyName: 'noop' })
|
||||
const mergedOption = getComponentOption({ keyName: 'noop' }, component)
|
||||
expect(mergedOption).toEqual({})
|
||||
})
|
||||
|
||||
test('fetches the given option from the given component', () => {
|
||||
const component = new Vue({ someOption: { foo: 'bar' } })
|
||||
const mergedOption = getComponentOption({ component, keyName: 'someOption' })
|
||||
const mergedOption = getComponentOption({ keyName: 'someOption' }, component)
|
||||
expect(mergedOption.foo).toBeDefined()
|
||||
expect(mergedOption.foo).toEqual('bar')
|
||||
})
|
||||
@@ -27,7 +27,7 @@ describe('getComponentOption', () => {
|
||||
return { opt: this.$options.name }
|
||||
}
|
||||
})
|
||||
const mergedOption = getComponentOption({ component, keyName: 'someFunc' })
|
||||
const mergedOption = getComponentOption({ keyName: 'someFunc' }, component)
|
||||
// TODO: Should this be foobar or Foobar
|
||||
expect(mergedOption.opt).toBeDefined()
|
||||
expect(mergedOption.opt).toEqual('Foobar')
|
||||
@@ -44,7 +44,7 @@ describe('getComponentOption', () => {
|
||||
|
||||
const wrapper = mount(component, { localVue })
|
||||
|
||||
const mergedOption = getComponentOption({ component: wrapper.vm, keyName: 'foo' })
|
||||
const mergedOption = getComponentOption({ keyName: 'foo' }, wrapper.vm)
|
||||
expect(mergedOption).toEqual({ bar: 'baz', fizz: 'buzz' })
|
||||
})
|
||||
|
||||
@@ -111,7 +111,7 @@ describe('getComponentOption', () => {
|
||||
|
||||
const wrapper = mount(component, { localVue })
|
||||
|
||||
const mergedOption = getComponentOption({ component: wrapper.vm, keyName: 'foo' })
|
||||
const mergedOption = getComponentOption({ keyName: 'foo' }, wrapper.vm)
|
||||
|
||||
expect(mergedOption).toEqual({ bar: 'baz' })
|
||||
expect(wrapper.vm.$children[0]._vueMeta).toBe(true)
|
||||
|
||||
Reference in New Issue
Block a user