Skip to content

Commit b6a12a8

Browse files
authored
fix: avoid to inherit __decorators__ property to sub classes (#200)
1 parent 2bc36c5 commit b6a12a8

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/component.ts

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export function componentFactory (
5858
const decorators = (Component as DecoratedClass).__decorators__
5959
if (decorators) {
6060
decorators.forEach(fn => fn(options))
61+
delete (Component as DecoratedClass).__decorators__
6162
}
6263

6364
// find super

test/test.ts

+33
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Component, { createDecorator } from '../lib'
22
import { expect } from 'chai'
3+
import * as td from 'testdouble'
34
import Vue, { ComputedOptions } from 'vue'
45

56
describe('vue-class-component', () => {
@@ -187,6 +188,38 @@ describe('vue-class-component', () => {
187188
expect(a.b).to.equal(2)
188189
})
189190

191+
// #199
192+
it('should not re-execute super class decortors', function (done) {
193+
const Watch = (valueKey: string) => createDecorator((options, key) => {
194+
if (!options.watch) {
195+
options.watch = {}
196+
}
197+
options.watch[valueKey] = key
198+
})
199+
200+
const spy = td.function()
201+
202+
@Component
203+
class Base extends Vue {
204+
count = 0
205+
206+
@Watch('count')
207+
notify () {
208+
spy()
209+
}
210+
}
211+
212+
@Component
213+
class A extends Base {}
214+
215+
const vm = new A()
216+
vm.count++
217+
vm.$nextTick(() => {
218+
td.verify(spy(), { times: 1 })
219+
done()
220+
})
221+
})
222+
190223
it('createDecorator', function () {
191224
const Prop = createDecorator((options, key) => {
192225
// component options should be passed to the callback

0 commit comments

Comments
 (0)