Skip to content

refactor(schema): convert the schema slice to signals (finishes #88) (#91)#93

Merged
BorisTyshkevich merged 1 commit into
mainfrom
refactor/schema-signals-91
Jun 30, 2026
Merged

refactor(schema): convert the schema slice to signals (finishes #88) (#91)#93
BorisTyshkevich merged 1 commit into
mainfrom
refactor/schema-signals-91

Conversation

@BorisTyshkevich

Copy link
Copy Markdown
Collaborator

What & why

Final slice of the #88 reactivity migration (ADR-0001): convert the schema panel's state to @preact/signals-core. schema / schemaError / schemaFilter become signal(...), and the in-place mutation the ADR flagged as the "awkward slice" is removed — without adopting Preact (that spike was rejected; the panel stays a documented imperative exception, ADR-0001 addendum). No user-facing change.

Approach (chosen "C" — reviewed by an independent Plan agent)

  • Expand state: db.expanded (mutated bool) + the expandedTables Set → one Set-valued expanded signal (keys db:/tb:), updated copy-on-write via a local toggleKey helper.
  • Column loads: loadColumns now replaces the schema reference ({...tb, columns}) instead of mutating tb.columns in place. tb.columns stays the completion cache buildCompletions reads — so completions.js is untouched (lower churn than a separate Map-valued signal, and the core gate stays at 100%). loadColumns drops its now-unused tableObj param.
  • Repaint: two effect()s in createApp (schema tree + error banner) replace every scattered renderSchema() call. The expand + first column-fetch is wrapped in batch() so the row opens with its spinner in one repaint; loadSchema's schema+error writes are batched too.

Notes

  • The vestigial expanded:false produced by ch-client.loadSchema is left as-is (out of this slice's listed scope; nothing reads db.expanded anymore).
  • Self-review (code-review high) surfaced two cleanups: applied the dbKey/tbKey reuse (single source of truth for the expand-vs-dblclick key); left the ch-client field per scope.

Checklist

  • npm test passes (per-file 100% gate; 1028 tests) — schema.js 100/100/100/100
  • Tests added/updated in the same change (schema/app/state specs swept to .value + expanded Set keys; completions.test.js untouched)
  • npm run build succeeds (single-file dist/sql.html)
  • Layers kept honest (no new dep; signals in state, imperative render in src/ui)
  • No new runtime dependency
  • CHANGELOG.md ([Unreleased]) updated
  • Reconciled tracked work: ADR-0001 addendum + CHANGELOG; completes Adopt reactivity via @preact/signals-core, incrementally (ADR-0001) #88
  • e2e green on Chromium / Firefox / WebKit (39 passed)

Closes #91. Part of #68 (Phase 1). Completes #88 — the reactivity migration is done; #88 can be closed on merge.

🤖 Generated with Claude Code

Converts the schema panel's state to @preact/signals-core, the last slice of
the #88 reactivity migration. `schema`/`schemaError`/`schemaFilter` become
`signal(...)`; the in-place anti-pattern the ADR flagged is removed two ways:

- per-row expand state moves from the mutated `db.expanded` bool + the
  `expandedTables` Set into one Set-valued `expanded` signal (keys `db:`/`tb:`),
  updated copy-on-write via a `toggleKey` helper;
- lazy column loads replace the `schema` reference (`{...tb, columns}`) instead
  of mutating `tb.columns` in place. `tb.columns` stays the completion cache
  `buildCompletions` reads, so `completions.js` is untouched (lower churn than a
  separate Map-valued signal — the chosen "Approach C").

Two `effect()`s in `createApp` (schema tree + error banner) replace every
scattered `renderSchema()` call; the expand+first-fetch is wrapped in `batch()`
so the row opens with its spinner in a single repaint, and `loadSchema`'s
schema+error writes are batched too. The panel stays imperative — no Preact
(spike rejected, ADR-0001 addendum). No user-facing change.

`loadColumns` drops its now-unused `tableObj` param (it locates the table by
db/table name and replaces by reference). The vestigial `expanded:false` from
ch-client's loadSchema is left as-is (out of this slice's scope).

Tests swept to `.value` + the `expanded` Set keys across schema/app/state specs;
`completions.test.js` untouched. Per-file 100% gate holds; build clean; e2e green
on Chromium/Firefox/WebKit.

Reconciles CHANGELOG [Unreleased] + the ADR addendum; completes the #88 migration.

Closes #91. Part of #68 (Phase 1). Completes #88.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@BorisTyshkevich BorisTyshkevich merged commit 2b5af6c into main Jun 30, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Convert the schema slice to signals (schema/schemaError/schemaFilter) — Phase 1 of #88

1 participant