* Subscribe to cache changes for a specific key. Used by useSyncExternalStore.
(key: string, callback: () => void)
| 60 | * Subscribe to cache changes for a specific key. Used by useSyncExternalStore. |
| 61 | */ |
| 62 | function subscribeToKey(key: string, callback: () => void): () => void { |
| 63 | let listeners = cache.keyListeners.get(key) |
| 64 | if (!listeners) { |
| 65 | listeners = new Set() |
| 66 | cache.keyListeners.set(key, listeners) |
| 67 | } |
| 68 | listeners.add(callback) |
| 69 | return () => { |
| 70 | listeners!.delete(callback) |
| 71 | if (listeners!.size === 0) { |
| 72 | cache.keyListeners.delete(key) |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Snapshot includes BOTH entry + isFetching, and is memoized so Object.is only changes |
no test coverage detected