refactor: move writable check out of computed setter (#112)
This commit is contained in:
parent
0bdee72e17
commit
caa9297da6
@ -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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user