Skip to content

Conversation

@franknoirot
Copy link
Contributor

Building upon #9058 (and #9056 by extension), towards #8880. We had this KclContextProvider component that gets around the difficulties with subscribing to updates to class properties by:

  1. Establishing a React Context provider
  2. Establishing React useStates which receive their initial values from the kclManager class instance's property values
  3. Using a useEffect to wire up a series of "set" listener callbacks within kclManager that are fired within the setters for each of those properties, which then sets the React state proxies in KclContextProvider, which consumers of the context can subscribe to reactively.
Rick & Morty: Well that just sounds like (replaced text) signals with extra steps

So if we install @preact/signals-core and its corresponding bundler plugin for React we can get this sort of thing for far fewer lines of code. If you all like this I would like to propose it as a pattern we adopt, where state is kept outside of React in these classes and objects that interact, but React can subscribe to the "public" API of those state objects by wrapping them in Preact Signals.

Users should experience no difference with this refactor.

@vercel
Copy link

vercel bot commented Nov 26, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
modeling-app Ready Ready Preview Comment Nov 29, 2025 6:00am

@franknoirot franknoirot changed the title Remove KclProvider, replace it's listener pattern with Preact Signals Remove KclProvider, replace its listener pattern with Preact Signals Nov 26, 2025
@franknoirot franknoirot force-pushed the franknoirot/8880/kill-another-manager branch from d347a8e to ed652e2 Compare November 27, 2025 03:15
@franknoirot franknoirot force-pushed the franknoirot/8880/kill-another-manager branch from ed652e2 to b8c5287 Compare November 27, 2025 04:00
We need it to wait until <App/> mounts to fire
@franknoirot franknoirot force-pushed the franknoirot/8880/kill-a-provider branch from b4be5ad to a6ed618 Compare November 27, 2025 05:07
Base automatically changed from franknoirot/8880/kill-another-manager to main November 27, 2025 12:23
sourceRange?: SourceRange
selectionRanges: Selections
allowArrays?: boolean
code: string
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is code a new parameter here instead of using kclManager.codeSignal.value?
Is it because it doesn't always use that but a new / modified code which is not yet in kclManager? If that's the case it's not a problem that the ast and variables are still being picked up from kclManager in this function?

Copy link
Contributor

@andrewvarga andrewvarga left a comment

Choose a reason for hiding this comment

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

I've never used preact signals before but they seem very handy.
I agree that if we move more of our state to signals it can simplify accessing that state, and make the state less tightly coupled to React as well.
Maybe even move some state out of xstate to signals.

Do you see any downsides to using them so far?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants