Cretezy / redux_persist

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

Can't seem to save a more complex state #40

Closed ArthurianX closed 5 years ago

ArthurianX commented 5 years ago

Hey @Cretezy,

first of all, thanks for this library, it's nice to have all these over to dart!

I seem to have a problem persisting data - I'm REALLY new at dart - I got the serialization down and working I believe, fixed all the errors, but the data doesn't seem to save.

It's an open repo, https://github.com/ArthurianX/g4media-mobile/blob/master/lib/main.dart, I'm not sure where the problem lays, I tried debugging it from both ends, saving the data, I added breakpoints deep with the libraries and the data seem to save, but when the state is getting restored, it's the initial one.

Being a beginner at Dart, I might reset / reinstantiate my store somewhere along the way but I'm not seeing it, so I'm not sure if it's a library issue or a coding issue of mine.

G4Store I believe is being serialized properly, I have recursively added toJson and fromJson functionality, to the state itself, to the posts which are an instance of FetchPostsResult, and inside posts.items as well, which is a map of PostEntity items.

What could be the issue ?

Thanks a lot, Arthur

ArthurianX commented 5 years ago

Files of interest:

https://github.com/ArthurianX/g4media-mobile/blob/master/lib/main.dart - instantiation

https://github.com/ArthurianX/g4media-mobile/blob/master/lib/src/state/g4_store.dart - store, serialization

https://github.com/ArthurianX/g4media-mobile/blob/master/lib/src/services/g4media_search_api.dart - serialization

https://github.com/ArthurianX/g4media-mobile/blob/master/lib/src/models/post_entity.dart - serialization

Cretezy commented 5 years ago

https://github.com/ArthurianX/g4media-mobile/blob/8e845560b8efa51d2b5cbc52af28cd423f162605/lib/src/state/g4_store.dart#L60 and https://github.com/ArthurianX/g4media-mobile/blob/8e845560b8efa51d2b5cbc52af28cd423f162605/lib/src/state/g4_store.dart#L68 seems wrong. It should be the inverse.

I can't really seem to see what's wrong with the overall program though. Could you run the app, trigger a save (dispatch anything), and extract the saved JSON from the device? (Not sure how to do on iOS, but in Android + IntelliJ you have a device viewer) You can also just read from the file in the Dart code. If you can post it here we could see a bit clearer what's being saved/not restored.

ArthurianX commented 5 years ago

You were right about the inverse things, I missed that, still learning dart.

Also, I had to go through both ways of serialization of the json part. It works now, pushed the latest code.

Thanks a lot, closing this issue, it was human error :), mine.