Need help with state management (save+load) in Relm4 apps #507
Replies: 1 comment 3 replies
-
Reducer uses a subscription based approach, so you can't access the data directly. SharedState was designed for sharing (global) information across components.
I'm not sure if Relm4 has a proper solution for this problem yet. In general, sharing state in Rust is sometimes tricky. The most standard approach I can think of is I think this is a good example find missing features in Relm4, I hope we can come up with a satisfying solution. Maybe we should first take a step back and think about how you would ideally want to deal with game state and then come up with a solution to map this to Rust code. |
Beta Was this translation helpful? Give feedback.
-
I am currently trying to work out how Relm4 apps should persist and load state (e.g. to a file or to an HTTP API).
I see the following things in the Relm4 API, each of which looks like they might provide part of a solution, but none of them is a whole solution:
I am aware of the Subscriptions and Commands concepts in Elm, which Relm4 is (at least partially) based on, but I don't see how exactly they would translate into Relm4 - or if either of them has been implemented in Relm4 yet.
The
GAME_STATE
inexamples/libadwaita/tab_game.rs
helps a bit, but unfortunately not much, because the game state in that example is a single static global variable. This is not realistic because in many apps, state must be scoped and stored per-document or per-user, but the example doesn't show how you might pass a SharedState around within Components or attach it to them.I therefore need use some help in understanding how to put the pieces together to form, for example, a document-based app.
Example
This is a simplified tic-tac-toe example. It's incomplete at the moment; I'll need your help to complete it with the state management.
Some of the questions that immediately arise are:
fn init(...)
method?)Additionally, a more sophisticated version of this app could have multiple tabs/windows, where each Game is shown in its own window. How would the Game Reducer/SharedState be created for each window in this case?
(If we get this up to a good standard, we can then add a new page in the Relm book covering state management, with this as an example.)
Beta Was this translation helpful? Give feedback.
All reactions