You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TableCollectionView.svelte, BoardCollectionView.svelte, CalendarCollectionView.svelte, FieldManagerDialog.svelte, and /table/[id]/+page.svelte each independently re-implement the same boilerplate for reading a live Collection out of Yjs:
Call getCollectionView(doc, collectionId) (or getCollection) to get the current snapshot.
Subscribe collectionsMap.observeDeep/recordsMap.observeDeep in onMount to re-run step 1–2 on every Yjs change.
Unsubscribe on unmount.
This predates #96, but implementing #96's primaryFieldKey meant touching all five copies again to add one more mirrored field. Each copy is a small but exact duplicate of the others (see src/lib/components/BoardCollectionView.svelte's refresh()/onMount for the canonical shape), which is exactly the kind of drift risk this repo's service-layer/shared-projection conventions (docs/specifications/collection-views.md §3, service-layer.md) already try to avoid for other cross-cutting concerns.
Scope
Extract a shared reactive helper (e.g. useCollectionView(collectionId: () => string) in src/lib/data/ or src/lib/client/, using Svelte 5 runes) that encapsulates: initial read, Yjs observer subscription/cleanup, and exposes { schema, rows, primaryFieldKey, collection } as reactive state.
Migrate all five existing call sites (TableCollectionView, BoardCollectionView, CalendarCollectionView, FieldManagerDialog, /table/[id]/+page.svelte) to use it, deleting their individual refresh()/onMount observer boilerplate.
No behavior change — existing component tests should pass unmodified (or with only import/setup changes, not assertion changes).
Non-goals
Not a broader state-management rewrite (no store library, no global cache) — just deduplicating this one specific pattern.
Not changing what data is exposed (still schema/rows/primaryFieldKey) — a future PR can extend the helper if a sixth derived field shows up.
Done when
There is exactly one implementation of "read a Collection reactively from Yjs and keep it live," all five current call sites use it, and the existing test suite passes with no behavior change.
Problem
TableCollectionView.svelte,BoardCollectionView.svelte,CalendarCollectionView.svelte,FieldManagerDialog.svelte, and/table/[id]/+page.svelteeach independently re-implement the same boilerplate for reading a live Collection out of Yjs:getCollectionView(doc, collectionId)(orgetCollection) to get the current snapshot.schema,rows, and — since Make the Collection primary field and Board card title explicit #96 —primaryFieldKey) into local$statevariables.collectionsMap.observeDeep/recordsMap.observeDeepinonMountto re-run step 1–2 on every Yjs change.This predates #96, but implementing #96's
primaryFieldKeymeant touching all five copies again to add one more mirrored field. Each copy is a small but exact duplicate of the others (seesrc/lib/components/BoardCollectionView.svelte'srefresh()/onMountfor the canonical shape), which is exactly the kind of drift risk this repo's service-layer/shared-projection conventions (docs/specifications/collection-views.md§3,service-layer.md) already try to avoid for other cross-cutting concerns.Scope
useCollectionView(collectionId: () => string)insrc/lib/data/orsrc/lib/client/, using Svelte 5 runes) that encapsulates: initial read, Yjs observer subscription/cleanup, and exposes{ schema, rows, primaryFieldKey, collection }as reactive state.TableCollectionView,BoardCollectionView,CalendarCollectionView,FieldManagerDialog,/table/[id]/+page.svelte) to use it, deleting their individualrefresh()/onMountobserver boilerplate.Non-goals
Done when
There is exactly one implementation of "read a Collection reactively from Yjs and keep it live," all five current call sites use it, and the existing test suite passes with no behavior change.