Explorar o código

perf(reactivity): only call Set.add if doesn't already have value (#3307)

zhufengzhufeng %!s(int64=5) %!d(string=hai) anos
pai
achega
9cd988342c
Modificáronse 1 ficheiros con 1 adicións e 1 borrados
  1. 1 1
      packages/reactivity/src/collectionHandlers.ts

+ 1 - 1
packages/reactivity/src/collectionHandlers.ts

@@ -76,8 +76,8 @@ function add(this: SetTypes, value: unknown) {
   const target = toRaw(this)
   const proto = getProto(target)
   const hadKey = proto.has.call(target, value)
-  target.add(value)
   if (!hadKey) {
+    target.add(value)
     trigger(target, TriggerOpTypes.ADD, value, value)
   }
   return this