Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recommended way to get the state of a running app? #134

Open
walfie opened this issue Apr 13, 2020 · 0 comments
Open

Recommended way to get the state of a running app? #134

walfie opened this issue Apr 13, 2020 · 0 comments

Comments

@walfie
Copy link

walfie commented Apr 13, 2020

(alternate title: recommended way to do hot module replacement while persisting state?)

I'm trying to get hot module replacement working in my app during development, where I can persist the state of the app between source file edits.

The straightforward way to do this is by updating my init or main to accept an optional initial state and passing in the state from a previous reload if it exists. The issue is that there isn't a convenient way to get the current state of a running app from the "outside" (i.e., the thing that calls main).

What I'm currently doing is using the shutdown callback (which does have access to the model, and can be called from outside) to set a "global" ref, but it feels kinda hacky. An alternative I considered is using pushMsg and having a "give me the current state" message with some external channel to pass the state through, but that also feels unideal, for something that is only really used in development. Or, having each update call set some global ref.

Is there a recommended approach to doing this cleanly? Or maybe if there was a state()/getState()/whatever method that could be called on a running app

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

No branches or pull requests

1 participant