refactor: use faster key check

This commit is contained in:
Evan You
2018-10-17 12:20:54 -04:00
parent 30404ec546
commit 1c42c96d1a
5 changed files with 14 additions and 18 deletions

View File

@@ -1,5 +1,5 @@
import { ComponentInstance } from './component'
import { isString, isFunction } from '@vue/shared'
import { isFunction, isReservedKey } from '@vue/shared'
const bindCache = new WeakMap()
@@ -37,7 +37,7 @@ const renderProxyHandlers = {
) {
// computed
return target._computedGetters[key]()
} else {
} else if (key[0] !== '_') {
if (__DEV__ && !(key in target)) {
// TODO warn non-present property
}
@@ -57,7 +57,7 @@ const renderProxyHandlers = {
receiver: any
): boolean {
if (__DEV__) {
if (isString(key) && key[0] === '$') {
if (isReservedKey(key)) {
// TODO warn setting immutable properties
return false
}

View File

@@ -1,7 +1,6 @@
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
@@ -18,7 +17,7 @@ export function extractInitializers(
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]
}
}