diff --git a/src/component.ts b/src/component.ts index 78b1fb5..3188127 100644 --- a/src/component.ts +++ b/src/component.ts @@ -58,6 +58,7 @@ export function componentFactory ( const decorators = (Component as DecoratedClass).__decorators__ if (decorators) { decorators.forEach(fn => fn(options)) + delete (Component as DecoratedClass).__decorators__ } // find super diff --git a/test/test.ts b/test/test.ts index ada4451..0f1cfa1 100644 --- a/test/test.ts +++ b/test/test.ts @@ -1,5 +1,6 @@ import Component, { createDecorator } from '../lib' import { expect } from 'chai' +import * as td from 'testdouble' import Vue, { ComputedOptions } from 'vue' describe('vue-class-component', () => { @@ -187,6 +188,38 @@ describe('vue-class-component', () => { expect(a.b).to.equal(2) }) + // #199 + it('should not re-execute super class decortors', function (done) { + const Watch = (valueKey: string) => createDecorator((options, key) => { + if (!options.watch) { + options.watch = {} + } + options.watch[valueKey] = key + }) + + const spy = td.function() + + @Component + class Base extends Vue { + count = 0 + + @Watch('count') + notify () { + spy() + } + } + + @Component + class A extends Base {} + + const vm = new A() + vm.count++ + vm.$nextTick(() => { + td.verify(spy(), { times: 1 }) + done() + }) + }) + it('createDecorator', function () { const Prop = createDecorator((options, key) => { // component options should be passed to the callback