Skip to content

Commit 9951051

Browse files
author
RicardoErii
committed
fix(runtime-dom): functions returned should not support reuse
1 parent 4e7967f commit 9951051

File tree

1 file changed

+38
-44
lines changed
  • packages/runtime-dom/src/directives

1 file changed

+38
-44
lines changed

packages/runtime-dom/src/directives/vOn.ts

Lines changed: 38 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,16 @@ const modifierGuards: Record<
3535
export const withModifiers = <
3636
T extends (event: Event, ...args: unknown[]) => any
3737
>(
38-
fn: T & { _withMods?: T },
38+
fn: T,
3939
modifiers: string[]
4040
) => {
41-
return (
42-
fn._withMods ||
43-
(fn._withMods = ((event, ...args) => {
44-
for (let i = 0; i < modifiers.length; i++) {
45-
const guard = modifierGuards[modifiers[i]]
46-
if (guard && guard(event, modifiers)) return
47-
}
48-
return fn(event, ...args)
49-
}) as T)
50-
)
41+
return ((event, ...args) => {
42+
for (let i = 0; i < modifiers.length; i++) {
43+
const guard = modifierGuards[modifiers[i]]
44+
if (guard && guard(event, modifiers)) return
45+
}
46+
return fn(event, ...args)
47+
}) as T
5148
}
5249

5350
// Kept for 2.x compat.
@@ -66,7 +63,7 @@ const keyNames: Record<string, string | string[]> = {
6663
* @private
6764
*/
6865
export const withKeys = <T extends (event: KeyboardEvent) => any>(
69-
fn: T & { _withKeys?: T },
66+
fn: T,
7067
modifiers: string[]
7168
) => {
7269
let globalKeyCodes: LegacyConfig['keyCodes']
@@ -88,43 +85,40 @@ export const withKeys = <T extends (event: KeyboardEvent) => any>(
8885
}
8986
}
9087

91-
return (
92-
fn._withKeys ||
93-
(fn._withKeys = (event => {
94-
if (!('key' in event)) {
95-
return
96-
}
88+
return (event => {
89+
if (!('key' in event)) {
90+
return
91+
}
9792

98-
const eventKey = hyphenate(event.key)
99-
if (modifiers.some(k => k === eventKey || keyNames[k] === eventKey)) {
93+
const eventKey = hyphenate(event.key)
94+
if (modifiers.some(k => k === eventKey || keyNames[k] === eventKey)) {
95+
return fn(event)
96+
}
97+
98+
if (__COMPAT__) {
99+
const keyCode = String(event.keyCode)
100+
if (
101+
compatUtils.isCompatEnabled(
102+
DeprecationTypes.V_ON_KEYCODE_MODIFIER,
103+
instance
104+
) &&
105+
modifiers.some(mod => mod == keyCode)
106+
) {
100107
return fn(event)
101108
}
102-
103-
if (__COMPAT__) {
104-
const keyCode = String(event.keyCode)
105-
if (
106-
compatUtils.isCompatEnabled(
107-
DeprecationTypes.V_ON_KEYCODE_MODIFIER,
108-
instance
109-
) &&
110-
modifiers.some(mod => mod == keyCode)
111-
) {
112-
return fn(event)
113-
}
114-
if (globalKeyCodes) {
115-
for (const mod of modifiers) {
116-
const codes = globalKeyCodes[mod]
117-
if (codes) {
118-
const matches = isArray(codes)
119-
? codes.some(code => String(code) === keyCode)
120-
: String(codes) === keyCode
121-
if (matches) {
122-
return fn(event)
123-
}
109+
if (globalKeyCodes) {
110+
for (const mod of modifiers) {
111+
const codes = globalKeyCodes[mod]
112+
if (codes) {
113+
const matches = isArray(codes)
114+
? codes.some(code => String(code) === keyCode)
115+
: String(codes) === keyCode
116+
if (matches) {
117+
return fn(event)
124118
}
125119
}
126120
}
127121
}
128-
}) as T)
129-
)
122+
}
123+
}) as T
130124
}

0 commit comments

Comments
 (0)