mirror of
https://github.com/got-feedBack/feedBack.git
synced 2026-08-16 05:37:42 +00:00
feat(panes): panes.state(id) — let a plugin apply its own pane's values
mirrorGlobal covers the case where a pane drives a plain global that some renderer reads each frame. It does not cover the far more common one: a plugin whose MAIN-realm code is the authority — it clamps, it persists, it emits events, it owns the audio graph or the camera rig — and which must therefore APPLY the pane's values itself rather than have core splat them somewhere. Camera Director is the case that forced this. Its brain is the sole writer of the camera store, the sole broadcaster on splitscreen's channel, and the only thing that clamps an axis to its legal range. A pane cannot write window.__h3dCamCtl behind its back without desynchronising its presets, its persistence, and the panel's own sliders — and running the brain inside the pane realm would make it a SECOND store writer and a second broadcaster, racing the real one. So: `panes.state(id)` hands the main realm the open pane's store (get/set/all/subscribe). A plugin seeds it on `panes:opened`, subscribes, and applies what comes back through its own API. The pane stays realm-agnostic — it only ever touches ctx.state — and the plugin stays the single source of truth. For that to work, the hub now broadcasts EVERY change to the store, not just the ones a pane asked for: it subscribes to the store on connect rather than echoing pane-originated writes by hand. A value the plugin clamps or corrects therefore reaches the pane window immediately, and there is exactly one path by which state arrives in a pane — so it cannot drift. Signed-off-by: topkoa <topkoa@gmail.com>
This commit is contained in:
@@ -330,6 +330,29 @@
|
||||
// participate without a private import.
|
||||
registerHost,
|
||||
|
||||
// The main realm's handle on an open pane's state.
|
||||
//
|
||||
// `mirrorGlobal` covers the case where a pane drives a plain global that
|
||||
// some renderer reads. It does NOT cover the far more common one: a
|
||||
// plugin whose main-realm code is the authority — it clamps, it persists,
|
||||
// it emits events, it owns the audio graph or the camera rig — and which
|
||||
// therefore needs to APPLY the pane's values itself rather than have core
|
||||
// splat them somewhere.
|
||||
//
|
||||
// Such a plugin subscribes here on `panes:opened`, seeds the store with
|
||||
// its current values, and applies whatever comes back. The pane stays
|
||||
// realm-agnostic (it only ever touches ctx.state) and the plugin keeps
|
||||
// being the single source of truth. Returns null when the pane is closed.
|
||||
state: (id) => {
|
||||
const entry = open.get(id);
|
||||
return entry ? {
|
||||
get: (path) => entry.state.get(path),
|
||||
set: (path, value) => entry.state.set(path, value),
|
||||
all: () => entry.state.all(),
|
||||
subscribe: (fn) => entry.state.subscribe(fn),
|
||||
} : null;
|
||||
},
|
||||
|
||||
// Host-internal. pane-hub.js serves a pop-out realm from the
|
||||
// authoritative state store, which only lives here. Not part of the pane
|
||||
// API — panes must never reach for this.
|
||||
|
||||
Reference in New Issue
Block a user