Closed petermjones closed 6 years ago
I'm now thinking that apisauce monitors are the way to go, instead of a saga middleware.
For me, I think I'd go something that controls apisauce. As you mention, I feel like a saga is a better fit for this kinda thing.
Sounds like you're trying to build a cache of sorts. That to me shouldn't be shoehorned into it.
I've tried that approach and i was never happy with what I've built. =)
I'm using apisauce in a React Native project. Here is my current thinking (but hopefully you have a better idea):
Have the saga middleware make a special fake api call (one that does not actually make an http call) that sets the api global, api.needsUpdate = true, and have a timer at the root render that regularly polls things, like api.doWeNeedUpdate() (which would just return if needsUpdate is set), and set the some store state as needed (perhaps auth). That would be fairly easy and would cover all api calls. The only question is can a saga middleware call up the api?
Offline could be handled the same way (eventually setting a global state that can be polled).
Thoughts?