]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor(reactivity): reduce code of type check (#377)
authorJunyan <yancoding@gmail.com>
Fri, 25 Oct 2019 15:15:04 +0000 (23:15 +0800)
committerEvan You <yyx990803@gmail.com>
Fri, 25 Oct 2019 15:15:04 +0000 (11:15 -0400)
packages/reactivity/src/reactive.ts
packages/runtime-core/src/componentProps.ts
packages/shared/src/index.ts

index eec2eab1a68786908eb277c4c40d5d0a67012f08..7b168a3b80c0a03d2b919239bd40e86c4f2c2bf6 100644 (file)
@@ -1,4 +1,4 @@
-import { isObject, toTypeString } from '@vue/shared'
+import { isObject, toRawType } from '@vue/shared'
 import { mutableHandlers, readonlyHandlers } from './baseHandlers'
 import {
   mutableCollectionHandlers,
@@ -29,16 +29,14 @@ const nonReactiveValues = new WeakSet<any>()
 
 const collectionTypes = new Set<Function>([Set, Map, WeakMap, WeakSet])
 const isObservableType = /*#__PURE__*/ makeMap(
-  ['Object', 'Array', 'Map', 'Set', 'WeakMap', 'WeakSet']
-    .map(t => `[object ${t}]`)
-    .join(',')
+  'Object,Array,Map,Set,WeakMap,WeakSet'
 )
 
 const canObserve = (value: any): boolean => {
   return (
     !value._isVue &&
     !value._isVNode &&
-    isObservableType(toTypeString(value)) &&
+    isObservableType(toRawType(value)) &&
     !nonReactiveValues.has(value)
   )
 }
index 8f9e603e2703011b935fc98f92121fcbcb23601e..146e0ff3c0de3678eab84b598c93c93229ec11e7 100644 (file)
@@ -10,7 +10,7 @@ import {
   isObject,
   isReservedProp,
   hasOwn,
-  toTypeString,
+  toRawType,
   PatchFlags,
   makeMap
 } from '@vue/shared'
@@ -390,10 +390,6 @@ function styleValue(value: unknown, type: string): string {
   }
 }
 
-function toRawType(value: unknown): string {
-  return toTypeString(value).slice(8, -1)
-}
-
 function isExplicable(type: string): boolean {
   const explicitTypes = ['string', 'number', 'boolean']
   return explicitTypes.some(elem => type.toLowerCase() === elem)
index 5c7cc6a2ed83a861c8c27eb7780cc5ae49c0cdba..38b1e2920e153ee25c4dad4276ab0b79e52036c4 100644 (file)
@@ -48,6 +48,10 @@ export const objectToString = Object.prototype.toString
 export const toTypeString = (value: unknown): string =>
   objectToString.call(value)
 
+export function toRawType(value: unknown): string {
+  return toTypeString(value).slice(8, -1)
+}
+
 export const isPlainObject = (val: unknown): val is object =>
   toTypeString(val) === '[object Object]'