]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor: use regex instead of startsWith
authorEvan You <yyx990803@gmail.com>
Tue, 25 Sep 2018 16:06:19 +0000 (12:06 -0400)
committerEvan You <yyx990803@gmail.com>
Tue, 25 Sep 2018 16:06:19 +0000 (12:06 -0400)
packages/core/README.md
packages/core/src/componentProps.ts
packages/core/src/utils.ts
packages/core/src/vdom.ts
packages/renderer-dom/src/patchData.ts
packages/renderer-dom/src/teardownVNode.ts

index d5ff7d8708269fd812e9a3b91dc13fd036c6087a..ba699e902c64f0212824eb2a164ab74e47571f6d 100644 (file)
@@ -6,7 +6,6 @@
 import { createRenderer, h } from '@vue/core'
 
 const { render } = createRenderer({
-  queueJob,
   nodeOps,
   patchData,
   teardownVNode
index bd508b93d439049ba652e895f0d20ddbcce88eff..375a7155dbe2ec0db9da6d517f1f1266515dcb24 100644 (file)
@@ -1,4 +1,4 @@
-import { EMPTY_OBJ } from './utils'
+import { EMPTY_OBJ, nativeOnRE } from './utils'
 import {
   Component,
   ComponentClass,
@@ -100,7 +100,7 @@ export function resolveProps(
       if (
         key === 'class' ||
         key === 'style' ||
-        (isNativeOn = key.startsWith('nativeOn')) ||
+        (isNativeOn = nativeOnRE.test(key)) ||
         (hasDeclaredProps && !options.hasOwnProperty(key))
       ) {
         const newKey = isNativeOn ? 'on' + key.slice(8) : key
index 7b5011de47117a1e9738547024135befaa245f44..51eb0ec62d27be3166b297c3f4f2c32bb0af3359 100644 (file)
@@ -2,16 +2,11 @@ export const EMPTY_OBJ: { readonly [key: string]: any } = Object.freeze({})
 
 export const NOOP = () => {}
 
-export const isReservedProp = (key: string): boolean => {
-  switch (key) {
-    case 'key':
-    case 'ref':
-    case 'slots':
-      return true
-    default:
-      return key.startsWith('nativeOn')
-  }
-}
+export const onRE = /^on/
+export const nativeOnRE = /^nativeOn/
+
+const reserveRE = /^(?:key|ref|slots)$|^nativeOn/
+export const isReservedProp = (key: string): boolean => reserveRE.test(key)
 
 export function normalizeStyle(
   value: any
index c3481d9d916d7d7d1c526cb76b22d88af4b75a46..c5ef61afaf017a214c290ece27ece87658241acf 100644 (file)
@@ -5,7 +5,7 @@ import {
 } from './component'
 import { VNodeFlags, ChildrenFlags } from './flags'
 import { createComponentClassFromOptions } from './componentUtils'
-import { normalizeClass, normalizeStyle } from './utils'
+import { normalizeClass, normalizeStyle, onRE, nativeOnRE } from './utils'
 
 // Vue core is platform agnostic, so we are not using Element for "DOM" nodes.
 export interface RenderNode {
@@ -270,7 +270,7 @@ export function cloneVNode(vnode: VNode, extraData?: VNodeData): VNode {
           clonedData.class = normalizeClass([clonedData.class, extraData.class])
         } else if (key === 'style') {
           clonedData.style = normalizeStyle([clonedData.style, extraData.style])
-        } else if (key.startsWith('on')) {
+        } else if (onRE.test(key) || nativeOnRE.test(key)) {
           const existing = clonedData[key]
           clonedData[key] = existing
             ? [].concat(existing, extraData[key])
index 884d5c436c19de7ed42d2924c4994b159af5f6bf..803cfee1fb5e8a270850906ce3966ca77ce34d78 100644 (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),
index e1302c5e5e84aac68a2d6edf13302c237c7d5336..89d2fec6acccfdd6fee60621049534c94a2d4c6c 100644 (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)
       }
     }