Przeglądaj źródła

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

zhufengzhufeng 5 lat temu
rodzic
commit
9cd988342c
1 zmienionych plików z 1 dodań i 1 usunięć
  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