refactor: use faster key check
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user