From c486cce69c8f04cd6b027b48f1434032d5394514 Mon Sep 17 00:00:00 2001 From: ktsn Date: Tue, 28 Nov 2017 23:27:30 +0900 Subject: [PATCH] fix: avoid to inherit __decorators__ property to sub classes --- src/component.ts | 1 + test/test.ts | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/component.ts b/src/component.ts index 7cff457..a5f988e 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 4d04dbb..40bbfc9 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 @@ -274,13 +307,13 @@ describe('vue-class-component', () => { const vm: any = new MyComp() expect(vm.test).to.equal('foo') }) - + it('forwardStatics', function () { @Component class MyComp extends Vue { static myValue = 52 } - + expect(MyComp.myValue).to.equal(52); }) })