feat(runtime-core): support config.optionMergeStrategies

Note the behavior is different from Vue 2:
- merge strategies no longer apply to built-in options.
- the default value is now an empty object and no longer exposes merge
  strategies for built-in options.
This commit is contained in:
Evan You
2020-03-24 11:59:00 -04:00
parent 123738727a
commit 528621ba41
5 changed files with 82 additions and 11 deletions

View File

@@ -8,7 +8,8 @@ import {
nextTick,
renderToString,
ref,
defineComponent
defineComponent,
createApp
} from '@vue/runtime-test'
import { mockWarn } from '@vue/shared'
@@ -562,6 +563,28 @@ describe('api: options', () => {
expect(serializeInner(root)).toBe(`<div>1,1,3</div>`)
})
test('optionMergeStrategies', () => {
let merged: string
const App = defineComponent({
render() {},
mixins: [{ foo: 'mixin' }],
extends: { foo: 'extends' },
foo: 'local',
mounted() {
merged = this.$options.foo
}
})
const app = createApp(App)
app.mixin({
foo: 'global'
})
app.config.optionMergeStrategies.foo = (a, b) => (a ? `${a},` : ``) + b
app.mount(nodeOps.createElement('div'))
expect(merged!).toBe('global,extends,mixin,local')
})
describe('warnings', () => {
mockWarn()