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

Multipart state persistance mechanism #51

Open
AlexVegner opened this issue Jun 26, 2019 · 8 comments
Open

Multipart state persistance mechanism #51

AlexVegner opened this issue Jun 26, 2019 · 8 comments
Labels
enhancement New feature or request

Comments

@AlexVegner
Copy link

AlexVegner commented Jun 26, 2019

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
Copy link
Owner

Cretezy commented Jun 26, 2019

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

@Cretezy Cretezy added the enhancement New feature or request label Jun 26, 2019
@ciokan
Copy link

ciokan commented Jun 29, 2019

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
Copy link
Owner

Cretezy commented Jun 29, 2019

@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
Copy link

ciokan commented Jun 29, 2019

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

@Cretezy
Copy link
Owner

Cretezy commented Jun 29, 2019

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
Copy link

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
Copy link
Owner

Cretezy commented Sep 17, 2019

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
Copy link

YoofiBP commented Sep 18, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants