Skip to content

Commit d3cf61b

Browse files
committed
split into class.ts
1 parent 3c9b0c3 commit d3cf61b

File tree

5 files changed

+30
-31
lines changed

5 files changed

+30
-31
lines changed

src/class.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import type { ComponentPublicInstance } from 'vue'
2+
import type { OptionBuilder } from './optionBuilder'
3+
import type { IdentityType, Identity, IdentitySymbol } from './identity'
4+
export type VueCons<RawInstance extends Identity = Identity, IT extends IdentityType = { props: {}, events: {} }, Bundle = IT['props'] & { [index in keyof IT['events']as `on${Capitalize<index & string>}`]?: IT['events'][index] extends Function ? IT['events'][index] : { (param: IT['events'][index]): any } }> = {
5+
new(optionBuilder: OptionBuilder, vueInstance: any): ComponentPublicInstance<Bundle> & Identity<IT> & Omit<RawInstance, typeof IdentitySymbol>
6+
}
7+
8+
export const Base = class {
9+
constructor(optionBuilder: OptionBuilder, vueInstance: any) {
10+
const props = optionBuilder.props
11+
if (props) {
12+
Object.keys(props).forEach(key => {
13+
(this as any)[key] = vueInstance[key];
14+
})
15+
}
16+
const methods = optionBuilder.methods
17+
if (methods) {
18+
Object.keys(methods).forEach(key => {
19+
(this as any)[key] = methods[key].bind(vueInstance)
20+
})
21+
}
22+
}
23+
24+
} as VueCons

src/component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { build as optionVModel } from './option/vmodel'
1414
import { build as optionAccessor } from './option/accessor'
1515
import type { SetupContext } from 'vue';
1616
import type { OptionBuilder } from './optionBuilder'
17-
import type { VueCons } from './index'
17+
import type { VueCons } from './class'
1818
import * as DecoratorCompatible from './deco3/utils'
1919
export type Cons = VueCons
2020

src/index.ts

+2-27
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,8 @@ export { decorator as Vanilla } from './option/vanilla'
1111
export { decorator as Hook } from './option/methodsAndHooks'
1212
export { createDecorator } from './custom/custom'
1313
export { mixins } from './mixins'
14-
import type { ComponentPublicInstance } from 'vue'
15-
import type { OptionBuilder } from './optionBuilder'
1614
export { TSX } from './tsx/type'
17-
import type { IdentityType, Identity, IdentitySymbol } from './identity'
18-
19-
export type VueCons<RawInstance extends Identity = Identity, IT extends IdentityType = { props:{} , events: {} }, Bundle = IT['props'] & { [index in keyof IT['events']as `on${Capitalize<index & string>}`]?: IT['events'][index] extends Function ? IT['events'][index] : { (param: IT['events'][index]): any } }> = {
20-
new(optionBuilder: OptionBuilder, vueInstance: any): ComponentPublicInstance<Bundle> & Identity<IT> & Omit<RawInstance, typeof IdentitySymbol>
21-
}
22-
23-
export const Base = class {
24-
constructor(optionBuilder: OptionBuilder, vueInstance: any) {
25-
const props = optionBuilder.props
26-
if (props) {
27-
Object.keys(props).forEach(key => {
28-
(this as any)[key] = vueInstance[key];
29-
})
30-
}
31-
const methods = optionBuilder.methods
32-
if (methods) {
33-
Object.keys(methods).forEach(key => {
34-
(this as any)[key] = methods[key].bind(vueInstance)
35-
})
36-
}
37-
}
38-
39-
} as VueCons
40-
15+
import { Base } from './class'
16+
export { Base }
4117
export const Vue = Base
42-
4318
export { toNative } from './component'

src/mixins.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ComponentBase } from './component'
22
import { obtainSlot } from './utils'
3-
import type { VueCons } from './index'
3+
import type { VueCons } from './class'
44
import { Vue } from './index'
55
import type { MergeIdentityType, IdentitySymbol } from './identity'
66
type MixedClass<Mixins extends VueCons[], Base extends VueCons = VueCons> =
@@ -13,8 +13,8 @@ type MixedClass<Mixins extends VueCons[], Base extends VueCons = VueCons> =
1313
Base
1414
export function mixins<T extends VueCons[]>(...conses: T) {
1515
class MixinsClass extends Vue {
16-
1716
}
17+
1818
ComponentBase({
1919
mixins: conses.map((cons => obtainSlot(cons.prototype).cachedVueComponent))
2020
})(MixinsClass)

src/tsx/type.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { IdentityType, MergeIdentityType, IdentitySymbol } from '../identity'
2-
import type { VueCons } from '../index'
2+
import type { VueCons } from '../class'
33

44
export function TSX<Properties extends IdentityType['props'] = {}, Events extends IdentityType['events'] = {}, IT extends IdentityType = {
55
props: Properties

0 commit comments

Comments
 (0)