Fix infinite render loop, fix repertoire entry removal

This commit is contained in:
2025-10-10 15:30:41 +02:00
parent 6ea21aa0f1
commit 4b1f7c260b
3 changed files with 4 additions and 4 deletions

View File

@@ -79,7 +79,7 @@ interface CacheInterface<K, A, E> {
/**
* Retrieve the state currently stored in the cache for a given `key`.
*/
readonly getCurrent: (key: K) => Option.Option<State<A, E>>;
readonly getCurrent: (key: K) => State<A, E> | undefined;
/**
* Set or update the value currently stored in the cache for a given `key`
* and return the updated value. Running this effect while the state is
@@ -163,7 +163,7 @@ export const make = <K, A, E>(fetchFn: FetchFn<K, A, E>): Cache<K, A, E> => {
});
});
const getCurrent = (key: K) => Option.fromNullable(stateMap.get(key));
const getCurrent = (key: K) => stateMap.get(key);
const update = (key: K, action: Update<A>) => Effect.suspend(() => {
const state = stateMap.get(key);

View File

@@ -54,7 +54,7 @@ export function useCache<K, A, E>(cache: Cache.Cache<K, A, E>, key: NoInfer<K>):
const subscribe = useMemo(() => cache.subscribe.bind(undefined, key), [cache.subscribe, key]);
const selector = useCallback(() => cache.getCurrent(key), [cache.getCurrent, key]);
const state = useSyncExternalStore(subscribe, selector);
const state = Option.fromNullable(useSyncExternalStore(subscribe, selector));
useLayoutEffect(() => { Effect.runFork(cache.get(key)); }, [cache.get, key]);

View File

@@ -199,7 +199,7 @@ function EntryRow({
const removeAction = (entries: readonly Piece[]) => pipe(
entries,
Array.filter((p) => p.pieceId !== piece.pieceId),
Array.remove(no - 1),
);
const update = (action: (prev: readonly Piece[]) => readonly Piece[]) => Effect.gen(function* () {