From 63228fd86a3d2085fd27ed5ac72236c483788a80 Mon Sep 17 00:00:00 2001 From: Aria Minaei Date: Thu, 1 Dec 2022 13:01:01 +0100 Subject: [PATCH] Simplify `prism.state()` --- packages/dataverse/src/derivations/prism/prism.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/dataverse/src/derivations/prism/prism.ts b/packages/dataverse/src/derivations/prism/prism.ts index 8aed326..89f3d7b 100644 --- a/packages/dataverse/src/derivations/prism/prism.ts +++ b/packages/dataverse/src/derivations/prism/prism.ts @@ -1,4 +1,3 @@ -import Box from '../../Box' import type Ticker from '../../Ticker' import type {$IntentionalAny, VoidFn} from '../../types' import Stack from '../../utils/Stack' @@ -489,17 +488,20 @@ class HotScope implements PrismScope { } state(key: string, initialValue: T): [T, (val: T) => void] { - const {b, setValue} = this.memo( + const {value, setValue} = this.memo( 'state/' + key, () => { - const b = new Box(initialValue) - const setValue = (val: T) => b.set(val) - return {b, setValue} + const value = {current: initialValue} + const setValue = (newValue: T) => { + value.current = newValue + this._hotHandle.forceStale() + } + return {value, setValue} }, [], ) - return [b.derivation.getValue(), setValue] + return [value.current, setValue] } sub(key: string): HotScope {