arqex / freezer

A tree data structure that emits events on updates, even if the modification is triggered by one of the leaves, making it easier to think in a reactive way.
MIT License
1.28k stars 56 forks source link

Store doesn't reset between launches. #109

Closed Billydubb closed 6 years ago

Billydubb commented 6 years ago

Using freezer in a React Native Android app, the store doesn't completely reset between launches.

I have a store that has an object called projects

projects: {}.

When I launch the app for the very first time (fresh install) and print out all projects I get an empty object as expected. I then fill the project object with, say, 10 projects, where the object key is the project ID and the value is some project object.

If I now kill and restart the app (no reinstall), and print out all projects as the first action, I get an object with 10 projects, with their keys ranging from 0 - 10, rather than being the project IDs I used to originally save those projects.

Shouldn't the store be deleted on an app restart?

arqex commented 6 years ago

Hi @Billydubb

I am not a react native expert, but it looks to me like the context of the app is not really killed when you close it. To be honest I have no idea about how Android closes the apps, but if it doesn't clean the JS context automatically, maybe you can use some android signal to the app (some event when the app get closed or open) and clean it yourself. That way you will be sure that you will get a fresh store on opening.

Billydubb commented 6 years ago

Issue can be closed. It is indeed reset between launches. I overlooked that I loaded the projects from persistent database on startup and put them into the storage without giving them their IDs as keys. Stupid mistake.