* Snapshot includes BOTH entry + isFetching, and is memoized so Object.is only changes * when either changes. This fixes "notify but no rerender" when only fetch-status changes.
(key: string)
| 79 | * when either changes. This fixes "notify but no rerender" when only fetch-status changes. |
| 80 | */ |
| 81 | function getKeySnapshot<T>(key: string): KeySnapshot<T> { |
| 82 | const entry = cache.entries.get(key) as CacheEntry<T> | undefined |
| 83 | const fetching = cache.fetchingKeys.has(key) |
| 84 | |
| 85 | const memo = snapshotMemo.get(key) |
| 86 | if (memo && memo.entryRef === (entry as any) && memo.fetching === fetching) { |
| 87 | return memo.snap as KeySnapshot<T> |
| 88 | } |
| 89 | |
| 90 | const snap: KeySnapshot<T> = { entry, isFetching: fetching } |
| 91 | snapshotMemo.set(key, { |
| 92 | entryRef: entry as any, |
| 93 | fetching, |
| 94 | snap: snap as any, |
| 95 | }) |
| 96 | return snap |
| 97 | } |
| 98 | |
| 99 | function setCacheEntry<T>(key: string, entry: CacheEntry<T>): void { |
| 100 | cache.entries.set(key, entry as CacheEntry<unknown>) |
no test coverage detected