Skip to content

Commit e765021

Browse files
committed
return cons
1 parent 7af01ee commit e765021

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-facing-decorator",
3-
"version": "2.1.8",
3+
"version": "2.1.9",
44
"description": "Vue typescript class and decorator based component.",
55
"main": "dist/index.js",
66
"keywords": [

src/component.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ function build(cons: Cons, option: ComponentOption) {
9393
}
9494
}
9595
const component = buildComponent(cons, option, superSlot === null ? undefined : superSlot.cachedVueComponent)
96+
component.__vfdConstructor = cons
9697
slot.cachedVueComponent = component
98+
9799
}
98100
function _Component(arg: ComponentConsOption, cb: (cons: Cons, option: ComponentOption) => any) {
99101
if (typeof arg === 'function') {
@@ -119,7 +121,9 @@ export function Component(arg: ComponentConsOption): any {
119121
// })
120122
// console.log('kkkk', '__vccOpts' in cons, cons)
121123
// return cons
122-
return obtainSlot(cons.prototype).cachedVueComponent
124+
let ff = obtainSlot(cons.prototype).cachedVueComponent
125+
126+
return ff
123127
})
124128

125129
}

src/index-return-cons.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export * from './index'
2+
import { Component as ComponentOld } from './index'
3+
export function Component(this: any) {
4+
const res = ComponentOld.apply(this, arguments as any)
5+
function process(res: any) {
6+
const cons = res.__vfdConstructor
7+
8+
cons.__vccOpts = res
9+
return cons
10+
}
11+
if (typeof res === 'function') {
12+
return function (this: any) {
13+
return process(res.apply(this, arguments as any))
14+
}
15+
} else {
16+
return process(res)
17+
}
18+
}

test/component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ describe('Component',
5858
Object.keys(EmptyContext).forEach(key => {
5959
if (key === 'data' && typeof EmptyContext[key] === 'function') {
6060
expect(true).to.equal(isEmptyObject(EmptyContext[key]()))
61-
}else if(key === 'beforeCreate' && typeof EmptyContext[key] === 'function'){
61+
} else if (key === 'beforeCreate' && typeof EmptyContext[key] === 'function') {
6262
expect(true).to.equal(isEmptyObject(EmptyContext[key]()))
63+
} else if (key === '__vfdConstructor') {
64+
expect('function').to.equal(typeof EmptyContext[key])
6365
} else {
6466

6567
expect(true).to.equal(isEmptyObject(EmptyContext[key]))

0 commit comments

Comments
 (0)