refactor: use regex instead of startsWith

This commit is contained in:
Evan You
2018-09-25 12:06:19 -04:00
parent 296164c207
commit 342a9f3a03
6 changed files with 16 additions and 18 deletions

View File

@@ -5,6 +5,9 @@ import { patchAttr } from './modules/attrs'
import { patchDOMProp } from './modules/props'
import { patchEvent } from './modules/events'
export const onRE = /^on/
const domPropsRE = /^domProps/
export function patchData(
el: Element,
key: string,
@@ -24,9 +27,9 @@ export function patchData(
patchStyle(el, prevValue, nextValue, nextVNode.data)
break
default:
if (key.startsWith('on')) {
if (onRE.test(key)) {
patchEvent(el, key.toLowerCase().slice(2), prevValue, nextValue)
} else if (key.startsWith('domProps')) {
} else if (domPropsRE.test(key)) {
patchDOMProp(
el,
key[8].toLowerCase() + key.slice(9),

View File

@@ -1,11 +1,12 @@
import { VNode } from '@vue/core'
import { handleDelegatedEvent } from './modules/events'
import { onRE } from './patchData'
export function teardownVNode(vnode: VNode) {
const { el, data } = vnode
if (data != null) {
for (const key in data) {
if (key.startsWith('on')) {
if (onRE.test(key)) {
handleDelegatedEvent(el, key.toLowerCase().slice(2), null)
}
}