Remove Box in favor of Atom

This commit is contained in:
Aria Minaei 2022-12-01 15:37:19 +01:00
parent 2bd1dc85a9
commit c354a602a4
13 changed files with 63 additions and 49 deletions

View file

@ -4,8 +4,8 @@
* @packageDocumentation
*/
import type {Prism} from '@theatre/dataverse'
import {Box} from '@theatre/dataverse'
import type { Prism} from '@theatre/dataverse';
import {Atom} from '@theatre/dataverse'
import {prism, val} from '@theatre/dataverse'
import {findIndex} from 'lodash-es'
import queueMicrotask from 'queue-microtask'
@ -58,17 +58,17 @@ export function usePrism<T>(
debugLabel?: string,
): T {
const fnAsCallback = useCallback(fn, deps)
const boxRef = useRef<Box<typeof fn>>(null as $IntentionalAny)
if (!boxRef.current) {
boxRef.current = new Box(fnAsCallback)
const atomRef = useRef<Atom<typeof fn>>(null as $IntentionalAny)
if (!atomRef.current) {
atomRef.current = new Atom(fnAsCallback)
} else {
boxRef.current.set(fnAsCallback)
atomRef.current.setState(fnAsCallback)
}
const prsm = useMemo(
() =>
prism(() => {
const fn = boxRef.current.prism.getValue()
const fn = atomRef.current.prism.getValue()
return fn()
}),
[],