Closed wtrocki closed 5 years ago
My understanding is that context providers in React are just a mechanism to define some stateful items such as an ApolloClient instance and make it really easy to access those within any part of the big hierarchy that is your React application.
I found I needed access to both the ApolloClient
that comes from offix-client and the actual OfflineClient
itself because it has certain properties (offlineStore) which are not directly accessible from the Apollo Client. It's not one vs the other but rather I needed both.
OffixProvider
is there to be able to pass the OfflineClient
class that you get as a result of offix.createClient.
This class has certain properties like offlineStore
, and certain methods like registerOfflineEventListener
which may be needed within the application. An example of this is in TaskService
(ported from the showcase) where we access the offlineStore.
I think the bigger question is does offix expose state and/or functionality other than the initialised Apollo Client that we might need to access within our application? If it does, we probably need a context provider for it. To me it looks like that is the case right now (based on direct usage of offlineStore) but perhaps that API will change in the future.
I think this is very important bug. To fix that we might simply make OffixClient extend apollo client (no reason why this needs to be separate) and reduce need of a separate provider. Can you create issue in offix. We can put that into the schedule
I think the main challenge right now is that the init
step performs what seems to be a bunch of asynchronous operations. In order to simply extend apollo client, we need to figure out how to make those steps synchronous. Or we'll probably need to create some kind of ready event/notification. I'll create an issue.
Forgot to link those in my previous comment: https://github.com/aerogear/offix/blob/master/packages/offix-client/src/OfflineClient.ts#L63-L78
Yes. Great idea. Init step is actually not needed and should be external. Lets put all that info into linked issue
Any benefits from OffixProvider vs using ApolloProvider?