]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor: move writable check out of computed setter (#112)
author扩散性百万甜面包 <himself65@outlook.com>
Sat, 5 Oct 2019 19:48:05 +0000 (03:48 +0800)
committerEvan You <yyx990803@gmail.com>
Sat, 5 Oct 2019 19:48:05 +0000 (15:48 -0400)
packages/reactivity/src/computed.ts

index 9ed42716dae45d5450c057b746894891f1f87801..3bb3c3e26d3933978bee3a0c87a6590af2b783f9 100644 (file)
@@ -28,7 +28,9 @@ export function computed<T>(
     ? (getterOrOptions as (() => T))
     : (getterOrOptions as WritableComputedOptions<T>).get
   const setter = isReadonly
-    ? null
+    ? () => {
+        // TODO warn attempting to mutate readonly computed value
+      }
     : (getterOrOptions as WritableComputedOptions<T>).set
 
   let dirty: boolean = true
@@ -57,12 +59,8 @@ export function computed<T>(
       trackChildRun(runner)
       return value
     },
-    set value(newValue) {
-      if (setter) {
-        setter(newValue)
-      } else {
-        // TODO warn attempting to mutate readonly computed value
-      }
+    set value(newValue: T) {
+      setter(newValue)
     }
   }
 }