refactor(reactivity): use function isSymbol instead of typeof (#155)

This commit is contained in:
Cr 2019-10-09 23:49:23 +08:00 committed by Evan You
parent b255f42ab3
commit b9a4d8d088

View File

@ -2,19 +2,19 @@ import { reactive, readonly, toRaw } from './reactive'
import { OperationTypes } from './operations' import { OperationTypes } from './operations'
import { track, trigger } from './effect' import { track, trigger } from './effect'
import { LOCKED } from './lock' import { LOCKED } from './lock'
import { isObject, hasOwn } from '@vue/shared' import { isObject, hasOwn, isSymbol } from '@vue/shared'
import { isRef } from './ref' import { isRef } from './ref'
const builtInSymbols = new Set( const builtInSymbols = new Set(
Object.getOwnPropertyNames(Symbol) Object.getOwnPropertyNames(Symbol)
.map(key => (Symbol as any)[key]) .map(key => (Symbol as any)[key])
.filter(value => typeof value === 'symbol') .filter(isSymbol)
) )
function createGetter(isReadonly: boolean) { function createGetter(isReadonly: boolean) {
return function get(target: any, key: string | symbol, receiver: any) { return function get(target: any, key: string | symbol, receiver: any) {
const res = Reflect.get(target, key, receiver) const res = Reflect.get(target, key, receiver)
if (typeof key === 'symbol' && builtInSymbols.has(key)) { if (isSymbol(key) && builtInSymbols.has(key)) {
return res return res
} }
if (isRef(res)) { if (isRef(res)) {