Skip to content

Commit 6de0db5

Browse files
committed
deco stage 3
1 parent a40e1bf commit 6de0db5

File tree

8 files changed

+43
-46
lines changed

8 files changed

+43
-46
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
},
2828
"author": "",
2929
"license": "MIT",
30-
"types": "dist/index.d.ts",
30+
3131
"peerDependencies": {
3232
"vue": "^3.0.0"
3333
},

src/deco3/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ export function compatibleClassDecorator(deco: Function) {
3232
export function compatibleMemberDecorator(deco: Function) {
3333
return function (arg: any, ctx: DecoratorContext | string) {
3434
if (typeof ctx === 'object') {//stage 3
35-
const proto = Compatible.fakePrototype ??= {}
35+
const proto = Compatible.fakePrototype ??= {};
36+
proto[ctx.name!] = arg
3637
return deco(proto, ctx.name)
3738
} else {
3839
return deco(arg, ctx)

src/index.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,15 @@ export type VueCons<T = {}> = {
3131

3232
export const Base = class {
3333
constructor(optionBuilder: OptionBuilder, vueInstance: any) {
34-
3534
const props = optionBuilder.props
36-
3735
if (props) {
3836
Object.keys(props).forEach(key => {
3937
(this as any)[key] = vueInstance[key];
4038
})
4139
}
42-
(global as any).kkk = this
43-
console.log('base', (this as any).prop)
44-
console.log('base', (global as any).kkk.prop)
45-
setTimeout(() => {
46-
console.log('base', (global as any).kkk.prop)
47-
}, 0);
40+
4841
}
42+
4943
} as VueCons
5044

5145
export const Vue = Base

src/option/data.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ import { makeObject, obtainSlot, excludeNames, getValidNames } from '../utils'
44

55
export function build(cons: Cons, optionBuilder: OptionBuilder, vueInstance: any, _propNames?: string[]) {
66
optionBuilder.data ??= {}
7-
console.log('build1')
8-
const sample = new cons(optionBuilder, vueInstance)
9-
// console.log('in build',sample)
10-
// let names = getValidNames(sample, (des) => {
11-
// return !!des.enumerable
12-
// })
137

14-
// const slot = obtainSlot(cons.prototype)
15-
// names = excludeNames(names, slot)
8+
const sample = new cons(optionBuilder,vueInstance)
169

17-
// Object.assign(optionBuilder.data, makeObject(names, sample))
10+
let names = getValidNames(sample, (des) => {
11+
return !!des.enumerable
12+
})
13+
14+
15+
const slot = obtainSlot(cons.prototype)
16+
names = excludeNames(names, slot)
17+
console.log(names)
18+
Object.assign(optionBuilder.data, makeObject(names, sample))
1819
}

src/option/watch.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface WatchConfig {
1313
type Option = Omit<WatchConfig, 'handler' | 'key'>
1414
export function decorator(key: string, option?: Option) {
1515
return compatibleMemberDecorator(function (proto: any, name: string) {
16+
console.log('watch deco',proto,name,option)
1617
const slot = obtainSlot(proto)
1718
const map = slot.obtainMap('watch');
1819
const opt = Object.assign({}, option ?? {}, {

test/option/data.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import { mount } from '@vue/test-utils'
66

77
@Component
88
class Comp extends Base {
9-
constructor(a:any,b:any){
10-
super(a,b)
11-
console.log("be",(global as any).kkk===this)
12-
}
9+
// constructor(a:any,b:any){
10+
// super(a,b)
11+
// console.log("be",(global as any).kkk===this)
12+
// }
1313
data = 'data value'
1414
@Prop
1515
prop!: string
16-
fieldInitProp = this.prop
16+
// fieldInitProp = this.prop //not work
1717
}
1818

1919
const CompContext = toNative(Comp) as any
@@ -28,9 +28,9 @@ describe('option data',
2828
}).vm
2929

3030
expect('function').to.equal(typeof CompContext?.data)
31-
// expect('data value').to.equal(CompContext.data().data)
32-
// expect(2).to.equal(Object.keys(CompContext.data()).length)
33-
expect('prop test').to.equal(vm.fieldInitProp)
31+
expect('data value').to.equal(CompContext.data().data)
32+
expect(1).to.equal(Object.keys(CompContext.data()).length)
33+
// expect('prop test').to.equal(vm.fieldInitProp)
3434
})
3535
}
3636
)

test/option/watch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Comp extends Base {
4242
}
4343
}
4444
const CompContext = toNative(Comp) as any
45-
45+
console.log(CompContext)
4646
describe('decorator Watch',
4747
() => {
4848
it('default', () => {

test/test.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
require('jsdom-global/keys.js').push('SVGElement')
22
require('jsdom-global')()
3-
// import './internal/utils'
4-
// import './component'
5-
// import './option/setup'
3+
import './internal/utils'
4+
import './component'
5+
import './option/setup'
66
import './option/data'
7-
// import './option/methods'
8-
// import './option/computed'
9-
// import './option/emit'
10-
// import './option/ref'
11-
// import './option/props'
12-
// import './option/watch'
13-
// import './option/inject'
14-
// import './option/vmodel'
15-
// import './option/accessor'
16-
// import './feature/hooks'
17-
// import './feature/classExtends'
18-
// import './feature/componentExtends'
19-
// import './feature/extends'
20-
// import './feature/mixinsFunction'
7+
import './option/methods'
8+
import './option/computed'
9+
import './option/emit'
10+
import './option/ref'
11+
import './option/props'
12+
import './option/watch'
13+
import './option/inject'
14+
import './option/vmodel'
15+
import './option/accessor'
16+
import './feature/hooks'
17+
import './feature/classExtends'
18+
import './feature/componentExtends'
19+
import './feature/extends'
20+
import './feature/mixinsFunction'
2121

2222

23-
// import './tsx/attributeTypes'
23+
import './tsx/attributeTypes'

0 commit comments

Comments
 (0)