Files
NapCatQQ/.pnpm-store/v3/files/5c/785b314a36a54fc4958d39a84940bc406fd52be47649d45c084fdfa385e6d2a902cd92959d38e142d1563da05a65457a98ae22bcc3d9d1459f90529a02766c
TanTan e311ca3275
Build NapCat Artifacts / Windows Loader Test (push) Canceled after 0s
Build NapCat Artifacts / Type Check & Test (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Framework (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Shell (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

42 lines
1019 B
Plaintext

// Duplicate some of the utils in `/src/utils` to ensure
// we don't end up dragging in larger chunks of the RTK core
// into the RTKQ bundle
export function getOrInsert<K extends object, V>(
map: WeakMap<K, V>,
key: K,
value: V,
): V
export function getOrInsert<K, V>(map: Map<K, V>, key: K, value: V): V
export function getOrInsert<K extends object, V>(
map: Map<K, V> | WeakMap<K, V>,
key: K,
value: V,
): V {
if (map.has(key)) return map.get(key) as V
return map.set(key, value).get(key) as V
}
export function getOrInsertComputed<K extends object, V>(
map: WeakMap<K, V>,
key: K,
compute: (key: K) => V,
): V
export function getOrInsertComputed<K, V>(
map: Map<K, V>,
key: K,
compute: (key: K) => V,
): V
export function getOrInsertComputed<K extends object, V>(
map: Map<K, V> | WeakMap<K, V>,
key: K,
compute: (key: K) => V,
): V {
if (map.has(key)) return map.get(key) as V
return map.set(key, compute(key)).get(key) as V
}
export const createNewMap = () => new Map()