From c3daa987ba57acee80fadb7eb25dcd910763d948 Mon Sep 17 00:00:00 2001 From: Matt Aitken Date: Mon, 14 Mar 2022 10:56:10 +0000 Subject: [PATCH] Change the cache to use Map --- app/hooks/useRelatedPaths.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/app/hooks/useRelatedPaths.ts b/app/hooks/useRelatedPaths.ts index ef1c371..3aa14f6 100644 --- a/app/hooks/useRelatedPaths.ts +++ b/app/hooks/useRelatedPaths.ts @@ -4,7 +4,7 @@ import { useJson } from "./useJson"; import { useJsonColumnViewState } from "./useJsonColumnView"; export function useRelatedPaths(): string[] { - const cache = useRef({}); + const cache = useRef(new Map>()); const { selectedNodeId } = useJsonColumnViewState(); const [json] = useJson(); @@ -12,7 +12,7 @@ export function useRelatedPaths(): string[] { if (!selectedNodeId) return []; //check cache - const cachedPaths = cache.current[selectedNodeId]; + const cachedPaths = cache.current.get(selectedNodeId); if (cachedPaths) { return cachedPaths; } @@ -23,13 +23,9 @@ export function useRelatedPaths(): string[] { //cache for (let index = 0; index < paths.length; index++) { const path = paths[index]; - cache.current[path] = paths; + cache.current.set(path, paths); } return paths; }, [selectedNodeId, json]); } - -type RelatedPathCache = { - [index: string]: Array; -};