Skip to content

Commit f60e9d3

Browse files
committed
+ correctly expose "methods"-option to recover compatibility to vue-class-component
1 parent d45a6b8 commit f60e9d3

File tree

4 files changed

+7
-14
lines changed

4 files changed

+7
-14
lines changed

src/component.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function buildComponent(cons: Cons, arg: ComponentOption, extend?: any): any {
7979
const option = ComponentOption(cons, extend)
8080
const slot = obtainSlot(cons.prototype)
8181
Object.keys(arg).reduce<Record<string, any>>((option, name: string) => {
82-
if (['options', 'modifier', 'emits', 'setup', 'provide'].includes(name)) {
82+
if (['options', 'modifier', 'methods', 'emits', 'setup', 'provide'].includes(name)) {
8383
return option
8484
}
8585
option[name] = arg[name as keyof ComponentOption]
@@ -93,12 +93,11 @@ function buildComponent(cons: Cons, arg: ComponentOption, extend?: any): any {
9393
}
9494
option.emits = emits
9595

96-
//apply methods
97-
let methods = Object.fromEntries(slot.obtainMap('methods'))
96+
//merge methods
9897
if ('object' === typeof arg.methods && !Array.isArray(arg.methods) && arg.methods !== null) {
99-
methods = Object.assign(methods, arg.methods);
98+
option.methods??={}
99+
Object.assign(option.methods, arg.methods);
100100
}
101-
option.methods = methods
102101

103102
//merge setup function
104103
if (!option.setup) {

src/option/emit.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ export function build(cons: Cons, optionBuilder: OptionBuilder) {
1818
return
1919
}
2020
const emits = slot.obtainMap('emits')
21-
const methods = slot.obtainMap('methods')
2221
names.forEach((value, key) => {
2322
const eventName = value === null ? key : value
2423
emits.set(eventName, true)
25-
26-
const emitFunction = async function (this: any) {
24+
optionBuilder.methods![key] = async function (this: any) {
2725

2826
const ret = proto[key].apply(this, arguments)
2927
if (ret instanceof Promise) {
@@ -34,7 +32,6 @@ export function build(cons: Cons, optionBuilder: OptionBuilder) {
3432
this.$emit(eventName, ret)
3533
}
3634
}
37-
optionBuilder.methods![key] = emitFunction
38-
methods.set(key, emitFunction)
3935
})
36+
4037
}

src/option/methodsAndHooks.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export function build(cons: Cons, optionBuilder: OptionBuilder) {
3333
const slot = obtainSlot(cons.prototype)
3434
const protoArr = toComponentReverse(cons.prototype)
3535
const hookMap = slot.obtainMap('hooks')
36-
const methodsMap = slot.obtainMap('methods')
3736

3837
optionBuilder.hooks ??= {}
3938
optionBuilder.methods ??= {}
@@ -48,14 +47,13 @@ export function build(cons: Cons, optionBuilder: OptionBuilder) {
4847
//watch, user may call watch method directly
4948
//hooks, user may call hook method directly
5049
//emits, user may have a method name which is same as one of event names
51-
return !['methods', 'watch', 'hooks', 'emits', 'provide'].includes(mapName)
50+
return !['watch', 'hooks', 'emits', 'provide'].includes(mapName)
5251
});
5352
names.forEach(name => {
5453
if (HookNames.includes(name) || hookMap.has(name)) {
5554
HookFunctions[name] = proto[name]
5655
} else {
5756
MethodFunctions[name] = proto[name]
58-
methodsMap.set(name, proto[name])
5957
}
6058
})
6159
})

src/utils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export type SlotMapTypes = {
2828
ref: Map<string, RefConfig>
2929
setup: Map<string, SetupConfig>
3030
customDecorator: Map<string, CustomDecoratorRecord[]>
31-
methods: Map<string, Function>
3231
}
3332

3433
class Slot {

0 commit comments

Comments
 (0)