refactor(v-on): avoid empty modifier guard with only key modifier

This commit is contained in:
Evan You
2019-10-18 16:20:45 -04:00
parent d69d3bf765
commit cba34453db
7 changed files with 47 additions and 30 deletions

View File

@@ -1,6 +1,6 @@
const systemModifiers = ['ctrl', 'shift', 'alt', 'meta']
type KeyedEvent = KeyboardEvent | MouseEvent | TouchEvent;
type KeyedEvent = KeyboardEvent | MouseEvent | TouchEvent
const modifierGuards: Record<
string,
@@ -20,7 +20,7 @@ const modifierGuards: Record<
systemModifiers.some(m => (e as any)[`${m}Key`] && !modifiers.includes(m))
}
export const vOnModifiersGuard = (fn: Function, modifiers: string[]) => {
export const withModifiers = (fn: Function, modifiers: string[]) => {
return (event: Event) => {
for (let i = 0; i < modifiers.length; i++) {
const guard = modifierGuards[modifiers[i]]
@@ -42,7 +42,7 @@ const keyNames: Record<string, string | string[]> = {
delete: 'backspace'
}
export const vOnKeysGuard = (fn: Function, modifiers: string[]) => {
export const withKeys = (fn: Function, modifiers: string[]) => {
return (event: KeyboardEvent) => {
if (!('key' in event)) return
const eventKey = event.key.toLowerCase()

View File

@@ -31,7 +31,7 @@ export {
vModelDynamic
} from './directives/vModel'
export { vOnModifiersGuard, vOnKeysGuard } from './directives/vOn'
export { withModifiers, withKeys } from './directives/vOn'
// re-export everything from core
// h, Component, reactivity API, nextTick, flags & types