diff --git a/packages/common/src/Cache.ts b/packages/common/src/Cache.ts index 2690e7a..9b434db 100644 --- a/packages/common/src/Cache.ts +++ b/packages/common/src/Cache.ts @@ -79,7 +79,7 @@ interface CacheInterface { /** * Retrieve the state currently stored in the cache for a given `key`. */ - readonly getCurrent: (key: K) => Option.Option>; + readonly getCurrent: (key: K) => State | 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 = (fetchFn: FetchFn): Cache => { }); }); - const getCurrent = (key: K) => Option.fromNullable(stateMap.get(key)); + const getCurrent = (key: K) => stateMap.get(key); const update = (key: K, action: Update) => Effect.suspend(() => { const state = stateMap.get(key); diff --git a/packages/frontend/src/hooks/useCache.ts b/packages/frontend/src/hooks/useCache.ts index 5213053..f4ec03f 100644 --- a/packages/frontend/src/hooks/useCache.ts +++ b/packages/frontend/src/hooks/useCache.ts @@ -54,7 +54,7 @@ export function useCache(cache: Cache.Cache, key: NoInfer): 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]); diff --git a/packages/frontend/src/routes/Repertoire.tsx b/packages/frontend/src/routes/Repertoire.tsx index dbc245f..37ddeb5 100644 --- a/packages/frontend/src/routes/Repertoire.tsx +++ b/packages/frontend/src/routes/Repertoire.tsx @@ -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* () {