util: Cleanup CachedValue class.

We use a Symbol for unassigned_value_sentinel and explictly assign
the compute_value property instead of using Object.assign. Both of
these are needed to type annotate it easily.
This commit is contained in:
Priyank Patel
2021-07-13 17:30:49 +00:00
committed by Tim Abbott
parent 288fe6d388
commit 899d7bba5a

View File

@@ -159,12 +159,12 @@ export const array_compare = function util_array_compare(a, b) {
* You must supply a option to the constructor called compute_value
* which should be a function that computes the uncached value.
*/
const unassigned_value_sentinel = {};
const unassigned_value_sentinel = Symbol("unassigned_value_sentinel");
export class CachedValue {
_value = unassigned_value_sentinel;
constructor(opts) {
Object.assign(this, opts);
this.compute_value = opts.compute_value;
}
get() {