/** * Key/checksum-based memoized version of `computed()`. * The provided `getKey()` function returns a cache key for each return value from `compute()`. * The computed signal will _not update_ for subsequent computed values that result in the same key. */ export function computedWithMemo( compute: () => T, getKey: (obj: T) => any, ) { let lastKey: T; let last: T; return computed(() => { const result = compute(); const key = getKey(result); if (last !== undefined && key === lastKey) return last; lastKey = key; last = result; return result; }); }