mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-28 18:19:28 +00:00
One shared `stableArray(prev, next)` helper replaces the duplicated element-equal/keep-prev logic in both stores, and freezes the shared ref so a future in-place mutation fails loud instead of silently corrupting the cache. Computed return type is now `readonly string[]` (it always was, immutably).
7 lines
547 B
TypeScript
7 lines
547 B
TypeScript
/** Keep `prev`'s reference when it's element-equal to `next`, so a nanostores
|
|
* `computed` (notifies on `!==`) skips the emit when its projected list didn't
|
|
* actually change — e.g. status-id sets recomputed on every stream delta.
|
|
* `next` is frozen: the ref is shared across ticks, so an in-place mutation
|
|
* would corrupt the cache — fail loud instead. */
|
|
export const stableArray = <T>(prev: readonly T[], next: T[]): readonly T[] =>
|
|
prev.length === next.length && prev.every((v, i) => v === next[i]) ? prev : Object.freeze(next)
|