From: 扩散性百万甜面包 Date: Sat, 5 Oct 2019 19:48:05 +0000 (+0800) Subject: refactor: move writable check out of computed setter (#112) X-Git-Tag: v3.0.0-alpha.0~591 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=caa9297da6ce828e62a17b07303cd761632a5074;p=thirdparty%2Fvuejs%2Fcore.git refactor: move writable check out of computed setter (#112) --- diff --git a/packages/reactivity/src/computed.ts b/packages/reactivity/src/computed.ts index 9ed42716da..3bb3c3e26d 100644 --- a/packages/reactivity/src/computed.ts +++ b/packages/reactivity/src/computed.ts @@ -28,7 +28,9 @@ export function computed( ? (getterOrOptions as (() => T)) : (getterOrOptions as WritableComputedOptions).get const setter = isReadonly - ? null + ? () => { + // TODO warn attempting to mutate readonly computed value + } : (getterOrOptions as WritableComputedOptions).set let dirty: boolean = true @@ -57,12 +59,8 @@ export function computed( 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) } } }