Skip to content

Host core: the controllable settings as a framework-free reducer and store - #145

Merged
agorischek merged 1 commit into
mainfrom
projection-store
Nov 21, 2026
Merged

agorischek merged 1 commit into
mainfrom
projection-store

Conversation

@agorischek

Copy link
Copy Markdown
Collaborator

This is step 1 of the projection store, G4 of the headless-host plan, following the design in docs/design/proposals/headless-store.md (#123). It starts now that #110, #115 and #122 have merged.

What changed

  • projection/settings-store.ts (new, no React) holds the rules for every setting an embedder may control:
    • initialSettings(options): each initial… option, else the definition's presentation, else the shared default;
    • settingValue: the embedder's value when it controls the setting, else the core's own;
    • requestedSettings: a requested change is kept only while the setting is uncontrolled. It returns the same object when nothing changes, so a refused change doesn't surface later.
    • notifySetting: the setting's on…Change is always called;
    • restartedSettings: a new subject resets the slider, stops playback and clears the selection. This was inline in use-projection.ts.
  • createSettingsStore(options) runs those rules without a framework: getSnapshot, subscribe, update, value, request and set.
  • useControllable runs the same functions in component state. Its exports and its latest, internal, setInternal, value and request keep their shapes, so callers don't change.

Why not useSyncExternalStore yet

use-projection.ts resets settings during render when the subject changes. With useState, React re-renders before committing. With an external store and a synchronous lane, the stale settings would commit for one frame, and the playback machine's effects would see them. So in this step, React keeps running the state, and the rules move. The switch to useSyncExternalStore comes in step 5, once everything lives in the store. The design note's steps 1 and 5 now say this.

Nothing new is exported. A public createProjection whose snapshot held only the settings would change shape at every step, so it arrives in step 5. The new tests import the module from dist, as other internal-module tests do.

Tests

packages/host/core/test/settings-store.test.mjs (node:test, no React, 4 tests) covers:

  • defaults, with presentation and initial… precedence, the speed clamp and the initial position;
  • uncontrolled requests: kept, notified, and published to subscribers once (a repeat isn't a change);
  • controlled requests: only notified, and a refused value doesn't surface when control is dropped;
  • the restart on a new subject.

Run locally:

  • tools check --fast: pass.
  • tsc for core: pass.
  • node --test on the new test with playback-lifecycle, paint and host: 24/24.

The browser suites run in CI.

…store

The first step of the projection store (docs/design/proposals/headless-store.md). The rules for the settings an
embedder may control (initial values, reading the embedder's or the core's value, requesting a change that is kept
only while uncontrolled and always reported, restarting on a new subject) move from `useControllable` into pure
functions in `projection/settings-store.ts`, with `createSettingsStore` to run them with `subscribe` outside React.
`useControllable` runs the same functions in component state, so React's timing doesn't change. Nothing new is
exported yet; the design note says when `createProjection` is.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the extraction of shared settings rules and the addition of the internal store.

No open issues 🎉

What changed in this PR

This implements the first step toward a framework-independent projection store by extracting controllable-setting rules from React while preserving the existing hook API and render-time reset behavior.

Changes:

  • Adds shared settings functions and an internal store with snapshots, subscriptions, and controlled/uncontrolled requests.
  • Reuses those functions in useControllable and subject-change resets without moving React state into an external store.
  • Adds framework-free tests and updates the plan to defer the public createProjection API until step 5.
File Description
packages/​host/​core/​test/​settings-store.test.mjs Tests initialization, requests, subscriptions, and restart behavior.
packages/​host/​core/​src/​projection/​use-projection.ts Delegates subject-change settings resets to the shared function.
packages/​host/​core/​src/​projection/​settings-store.ts Adds framework-free settings rules and the internal store.
packages/​host/​core/​src/​projection/​controllable.ts Reuses shared rules while retaining React state and existing exports.
docs/​design/​proposals/​headless-store.md Revises the implementation stages and public API timing.

Review effort: Balanced

@agorischek
agorischek merged commit e5a6a3d into main Nov 21, 2026
47 checks passed
@agorischek
agorischek deleted the projection-store branch November 21, 2026 17:27
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.

2 participants