Cretezy / redux_persist

Persist Redux State
https://pub.dartlang.org/packages/redux_persist
MIT License
130 stars 41 forks source link

Multipart state persistance mechanism #51

Open AlexVegner opened 5 years ago

AlexVegner commented 5 years ago

I would like to have ability to manage persistance for specific part of AppState. Examle:

class AppState {
   UserState userState;
   OfferSate offerState;
   OtherDataState otherDataState;
}

class UserState {
   String id;
   String fullName;
   ...
}

class OfferSate {
   List<Offers> offerList;
   ...
}

class OtherDataState {
  ...
}

persist userState to "UserState.json" file, and don't save it if it wasn't changed. persist offerState to "OfferSate.json" file, and don't save it if it wasn't changed. and don't persist otherDataState

Workarround: Now I need to split my state to multiple independent state objects. Hope you will implement better possibilities for my case.

Cretezy commented 5 years ago

This is definitely a good idea. I will take a look into seeing if this can be implemented easily.

ciokan commented 5 years ago

This should be a priority. I never done an app with redux that contained only primitives. All my app states point to different custom objects.

Cretezy commented 5 years ago

@ciokan I'm not sure if you understand this issue. The OP only wants to save difference portions of his state to different files.

You can serialize anything using this package. Your toJson method can return any data

ciokan commented 5 years ago

Oh. I thought that this plugin does not work work for state that is a bit nested.

Cretezy commented 5 years ago

It works very well for that. You can just call the nested object's toJson in your main toJson. If you have any other questions, feel free to open another ticket to keep this one on topic!

ianrothmann commented 5 years ago

Hi @Cretezy! Multipart state is a great idea. It slows the apps down quite a bit having to serialize everything with every action, especially if you have a large state object, of which a large part of the information does not change regularly. Let me know if you need any help.

Kind regards,

Ian

Cretezy commented 5 years ago

Sorry I haven't had a lot of time to work on this.

Due to how JSON is, it's all or nothing. I will try to come up for a way to have multiple save locations per key.

If you are storing a very large amount of data, I would highly suggest you use a hybrid approach and use a SQLite database as your storage mechanism instead of redux_persist, and load data dynamically. I've used this in one of my apps to a great success, but since it's more effort to implement, I would only suggest it for when you see performance issues with your app, or know you'll store a ton of data (100s of MBs or GBs)

YoofiBP commented 2 years ago

I would like to have ability to manage persistance for specific part of AppState. Examle:

class AppState {
   UserState userState;
   OfferSate offerState;
   OtherDataState otherDataState;
}

class UserState {
   String id;
   String fullName;
   ...
}

class OfferSate {
   List<Offers> offerList;
   ...
}

class OtherDataState {
  ...
}

persist userState to "UserState.json" file, and don't save it if it wasn't changed. persist offerState to "OfferSate.json" file, and don't save it if it wasn't changed. and don't persist otherDataState

Workarround: Now I need to split my state to multiple independent state objects. Hope you will implement better possibilities for my case.

Can you share an implementation for how you achieved this