inProgress-team / react-native-meteor

Meteor Reactivity for your React Native application :)
MIT License
693 stars 211 forks source link

Is it possible to save data to cache after subscribe? #36

Open radiegtya opened 8 years ago

radiegtya commented 8 years ago

For example:

How do you think @Mokto

Mokto commented 8 years ago

Yeah, why not !

I have to think about this but it is a good idea ;)

Thanks.

spencercarli commented 8 years ago

I'm doing something similar right now, well I was until my solution ended up not working, where I would write my cache (in that instance a redux store) to AsyncStorage whenever the app was put into the background (using AppState) or periodically.

The problem with AppState is that we can't listen to the close event (not just background) - it happens too fast and we can't fetch, stringify, and write data to AsyncStorage fast enough. Doing so periodically led to data being out of date and performance pains.

Would love to see other thoughts on this.

Mokto commented 8 years ago

We could observe minimongo collections and save items whenever the collection changes.

radiegtya commented 8 years ago

@mokto dunno that your solution will be run well, because what @spencercarli said is true. I have tested myself when using ddp-client npm package and minimongo, the data just too fast to be saved to async or store. I hope that you have better solution than me

Mokto commented 8 years ago

When you say the data is too fast to be saved to async, your mean that too much data is inserted into minimongo when the subscription is started, right ?

If it is the case, I have a ddp.on('ready') event available ;)

radiegtya commented 8 years ago

Dunno if I can help you to make it, for now I am only available for testing your plugin. Too many job on progress. I hope your minimongo able to do this ASAP. :D

radiegtya commented 8 years ago

any update to this @Mokto ?

Mokto commented 8 years ago

No and it will not be added soon, I have other things to do, sorry.

I'm currently trying react-native-meteor on a production app to stabilize it.

radiegtya commented 8 years ago

I've tested my self that almost all functionality work perfectly in my production apps, and what's missing is only this for now. So I hope this is also part of priority task although will not be added soon. Thanks @Mokto

funkyeah commented 8 years ago

I'm less interested in getting this solved soon but am interested in furthering the discussion.

@spencercarli what are the performance pains you mentioned above? Also referring to mokto's point above:

We could observe minimongo collections and save items whenever the collection changes.

Do you have any reason to think this wouldn't work sufficiently well performance-wise if you were using minimongo for caching data? Instead of saving periodic full snapshots of the collections we update asyncstorage whenever on the added, updated, removed collection events.

Alternatively I see realm is advertising faster speed than AsyncStorage for their react-native DB.

I saw https://github.com/rt2zz/redux-persist which might be more relevant to your use case... had you seen or tried that?

Ground DB is the biggest effort to make standard meteor and minimongo work offline. It uses localstorage so it probably could be adapted to AsyncStorage.

More generally properly invalidating, re-hydrating, and re-syncing anything other than immutable data seems like a really difficult challenge. I'm not even sure of the common approaches or pitfalls for doing those thing in mobile or web.

Anyone know more on that or some things to look at / read up on?