Fix infinite render loop, fix repertoire entry removal
This commit is contained in:
@@ -79,7 +79,7 @@ interface CacheInterface<K, A, E> {
|
|||||||
/**
|
/**
|
||||||
* Retrieve the state currently stored in the cache for a given `key`.
|
* 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`
|
* 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
|
* 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 update = (key: K, action: Update<A>) => Effect.suspend(() => {
|
||||||
const state = stateMap.get(key);
|
const state = stateMap.get(key);
|
||||||
|
|||||||
@@ -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 subscribe = useMemo(() => cache.subscribe.bind(undefined, key), [cache.subscribe, key]);
|
||||||
const selector = useCallback(() => cache.getCurrent(key), [cache.getCurrent, 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]);
|
useLayoutEffect(() => { Effect.runFork(cache.get(key)); }, [cache.get, key]);
|
||||||
|
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ function EntryRow({
|
|||||||
|
|
||||||
const removeAction = (entries: readonly Piece[]) => pipe(
|
const removeAction = (entries: readonly Piece[]) => pipe(
|
||||||
entries,
|
entries,
|
||||||
Array.filter((p) => p.pieceId !== piece.pieceId),
|
Array.remove(no - 1),
|
||||||
);
|
);
|
||||||
|
|
||||||
const update = (action: (prev: readonly Piece[]) => readonly Piece[]) => Effect.gen(function* () {
|
const update = (action: (prev: readonly Piece[]) => readonly Piece[]) => Effect.gen(function* () {
|
||||||
|
|||||||
Reference in New Issue
Block a user