Repository navigation
Host core: the controllable settings as a framework-free reducer and store - #145
Merged
Merged
Conversation
…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>
There was a problem hiding this comment.
🟢 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
useControllableand subject-change resets without moving React state into an external store. - Adds framework-free tests and updates the plan to defer the public
createProjectionAPI 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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): eachinitial…option, else the definition'spresentation, 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'son…Changeis always called;restartedSettings: a new subject resets the slider, stops playback and clears the selection. This was inline inuse-projection.ts.createSettingsStore(options)runs those rules without a framework:getSnapshot,subscribe,update,value,requestandset.useControllableruns the same functions in component state. Its exports and itslatest,internal,setInternal,valueandrequestkeep their shapes, so callers don't change.Why not
useSyncExternalStoreyetuse-projection.tsresets settings during render when the subject changes. WithuseState, 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 touseSyncExternalStorecomes 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
createProjectionwhose snapshot held only the settings would change shape at every step, so it arrives in step 5. The new tests import the module fromdist, as other internal-module tests do.Tests
packages/host/core/test/settings-store.test.mjs(node:test, no React, 4 tests) covers:presentationandinitial…precedence, the speed clamp and the initial position;Run locally:
tools check --fast: pass.tscfor core: pass.node --teston the new test withplayback-lifecycle,paintandhost: 24/24.The browser suites run in CI.