import { ComponentInstance } from './component'
-import { isString, isFunction } from '@vue/shared'
+import { isFunction, isReservedKey } from '@vue/shared'
const bindCache = new WeakMap()
) {
// computed
return target._computedGetters[key]()
- } else {
+ } else if (key[0] !== '_') {
if (__DEV__ && !(key in target)) {
// TODO warn non-present property
}
receiver: any
): boolean {
if (__DEV__) {
- if (isString(key) && key[0] === '$') {
+ if (isReservedKey(key)) {
// TODO warn setting immutable properties
return false
}
import { ComponentInstance } from './component'
import { observable } from '@vue/observer'
-
-const internalRE = /^_|^\$/
+import { isReservedKey } from '@vue/shared'
export function initializeState(instance: ComponentInstance) {
const { data } = instance.$options
const keys = Object.keys(instance)
for (let i = 0; i < keys.length; i++) {
const key = keys[i]
- if (!internalRE.test(key)) {
+ if (!isReservedKey(key)) {
data[key] = (instance as any)[key]
}
}
import { patchAttr } from './modules/attrs'
import { patchDOMProp } from './modules/props'
import { patchEvent } from './modules/events'
-import { onRE } from '@vue/shared'
+import { isOn } from '@vue/shared'
// value, checked, selected & muted
// plus anything with upperCase letter in it are always patched as properties
patchStyle(el, prevValue, nextValue, nextVNode.data)
break
default:
- if (onRE.test(key)) {
- patchEvent(
- el,
- key.replace(onRE, '').toLowerCase(),
- prevValue,
- nextValue
- )
+ if (isOn(key)) {
+ patchEvent(el, key.slice(2).toLowerCase(), prevValue, nextValue)
} else if (domPropsRE.test(key)) {
patchDOMProp(
el,
import { VNode } from '@vue/core'
import { handleDelegatedEvent } from './modules/events'
-import { onRE } from '@vue/shared'
+import { isOn } from '@vue/shared'
export function teardownVNode(vnode: VNode) {
const { el, data } = vnode
if (data != null) {
for (const key in data) {
- if (onRE.test(key)) {
- handleDelegatedEvent(el, key.toLowerCase().slice(2), null)
+ if (isOn(key)) {
+ handleDelegatedEvent(el, key.slice(2).toLowerCase(), null)
}
}
}
export const NOOP = () => {}
-export const onRE = /^on/
export const reservedPropRE = /^(?:key|ref|slots)$|^vnode/
+export const isOn = (key: string) => key[0] === 'o' && key[1] === 'n'
+export const isReservedKey = (key: string) => key[0] === '_' || key[0] === '$'
+
export const isArray = Array.isArray
export const isFunction = (val: any): val is Function =>
typeof val === 'function'