Organizing complex states for many different views #836
-
I'm making an application with many different views. Currently all my states are stored in my Application root object in a struct like so:
Some of these states are shared across views, others are not. But I'm about to change this to something more like this:
I think it would be really convenient to break this up by view page, each page getting it's own set of states and it's own struct. But now I'm wondering as my project grows, is it good for performance to instantiate every state for every page when the application loads? And is there another way to do this? Let's say I have 20 pages, then I will need to store a struct with 20 other structs within it. Or if there is 100 pages. Might this cause some issues? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
You probably do not need the state of all the different pages ready at once. I recommend you to use an enum to model the state of your pages. For instance: mod home;
mod login;
mod account;
pub use home::Home;
pub use login::Login;
pub use account::Account;
pub enum Page {
Home(Home),
Login(Login),
Account(Account),
// ...
} |
Beta Was this translation helpful? Give feedback.
-
Thanks. So I would use the enum by generating my page states for a given page after I received a message to switch pages in my update function, then assign this new generated state to my page enum? If I understand the process correctly. That is what makes sense to me right now anyway. |
Beta Was this translation helpful? Give feedback.
You probably do not need the state of all the different pages ready at once. I recommend you to use an enum to model the state of your pages. For instance: