refactor: move writable check out of computed setter (#112)

This commit is contained in:
扩散性百万甜面包 2019-10-06 03:48:05 +08:00 committed by Evan You
parent 0bdee72e17
commit caa9297da6

View File

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