Start extracting Tree component

This commit is contained in:
Gregory Schier
2026-03-08 16:37:25 -07:00
parent 6e11894f79
commit 6534421733
19 changed files with 344 additions and 151 deletions

View File

@@ -71,7 +71,20 @@ export function createModelStore<M extends ModelMap>(
);
}
return { dataAtom, applyChange, listAtom, orderedListAtom };
/** Replace all models of a given type. Used for initial hydration. */
function replaceAll<K extends keyof M & string>(
prev: StoreData<M>,
modelType: K,
models: M[K][],
): StoreData<M> {
const bucket = {} as Record<string, M[K]>;
for (const m of models) {
bucket[m.id] = m;
}
return { ...prev, [modelType]: bucket };
}
return { dataAtom, applyChange, replaceAll, listAtom, orderedListAtom };
}
function shallowEqual<T>(a: T[], b: T[]): boolean {