How to store clean view model states?

I’m working on a project that consists of a dashboard of widgets. When the user navigates away from the page, the view models of the widgets are stored so that when the user returns their dashboard loads up exactly how they left it.

The problem I’m having is some widgets need http client access. This http client then becomes a part of the model and a bunch of junk I don’t want gets stored.

What would be the best way to avoid this? Is there a way I can mark which model vars should or should not be stored? They are being stored as JSON string FYI.

I should mention that I thought about making some type of http-manager class to handle all this. But the only way I know to get a reference to it is to grab a reference to parent during the bind callback. This gives me a big junk parent object to store. :frowning:

Any help is greatly appreciated. :slight_smile:

I was overthinking this… Still learning! :slight_smile:

I would suggest that you split the state out of the view classes as this can become a pain later if for example later you you want to change the format of the stored data.

1 Like

Thats exactly what I ended up doing! :slight_smile:

Thanks for the suggestion!

I’ve ignored my own advice on this a couple of times as its much less code and normally much simpler to not split them but it always comes back to bite. :joy: