Skip to content

Commit

Permalink
fix(core): dedupe lifecycle hooks during options merge
Browse files Browse the repository at this point in the history
The fix landed in vuejs#9199 causes further extended constructors used as
mixins to drop options from its inheritance chain, so a different fix
is needed.
  • Loading branch information
yyx990803 authored and hefeng committed Jan 25, 2019
1 parent 7b7b34f commit 542a381
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/core/util/options.js
Expand Up @@ -395,7 +395,7 @@ export function mergeOptions (
}

if (typeof child === 'function') {
child = child.extendOptions
child = child.options
}

normalizeProps(child, vm)
Expand Down
38 changes: 21 additions & 17 deletions test/unit/features/options/mixins.spec.js
Expand Up @@ -110,31 +110,35 @@ describe('Options mixins', () => {
expect(vm.$options.directives.c).toBeDefined()
})

it('should not mix global mixined lifecycle hook twice', () => {
const spy = jasmine.createSpy('global mixed in lifecycle hook')
Vue.mixin({
created() {
spy()
}
})
it('should accept further extended constructors as mixins', () => {
const spy1 = jasmine.createSpy('mixinA')
const spy2 = jasmine.createSpy('mixinB')

const mixin1 = Vue.extend({
const mixinA = Vue.extend({
created: spy1,
directives: {
c: {}
},
methods: {
a() {}
a: function () {}
}
})

const mixin2 = Vue.extend({
mixins: [mixin1],
const mixinB = mixinA.extend({
created: spy2
})

const Child = Vue.extend({
mixins: [mixin2],
const vm = new Vue({
mixins: [mixinB],
methods: {
b: function () {}
}
})

const vm = new Child()

expect(typeof vm.$options.methods.a).toBe('function')
expect(spy.calls.count()).toBe(1)
expect(spy1).toHaveBeenCalledTimes(1)
expect(spy2).toHaveBeenCalledTimes(1)
expect(vm.a).toBeDefined()
expect(vm.b).toBeDefined()
expect(vm.$options.directives.c).toBeDefined()
})
})

0 comments on commit 542a381

Please sign in to comment.