| 60 | // "active"). Idle cache entries refetch on the next mount. |
| 61 | const keyAtoms = new Map<number, Set<Atom.Atom<AsyncResult.AsyncResult<any, any>>>>() |
| 62 | |
| 63 | const trackByKeys = |
| 64 | (keys: ReadonlyArray<ReadonlyArray<unknown>>) => |
| 65 | <A, E>(atom: Atom.Atom<AsyncResult.AsyncResult<A, E>>): Atom.Atom<AsyncResult.AsyncResult<A, E>> => |
| 66 | Atom.transform(atom, (get) => { |
| 67 | for (const key of keys) { |
| 68 | const h = Hash.hash(key) |
| 69 | let set = keyAtoms.get(h) |
| 70 | if (!set) keyAtoms.set(h, set = new Set()) |
| 71 | set.add(atom) |
| 72 | get.addFinalizer(() => { |
| 73 | set.delete(atom) |
| 74 | if (set.size === 0) keyAtoms.delete(h) |
| 75 | }) |
| 76 | } |
| 77 | return get(atom) |
| 78 | }, { initialValueTarget: atom }) |
| 79 | |