Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Client scoped query recyclers (#513) #876
I tried the code linking the package to my playground and it works, but I'm a bit lost with the test structure of the project and I don't really know how to write a test for this feature.
Also I'm also quite new to Apollo and I've never touched Typescript before so I really appreciate all the feedback you can give
Thanks for reviewing it @jbaxleyiii
I've been thinking about this isssue and having these WeakMaps all around as global application state seems kind of hackish. It works but I think there has to be a better solution.
Maybe a better approach would be to have a
@rcoedo I do think adding it to the context could be good, but I'm nervous about updating causing rerenders based on context updates. By keeping it out of the tree, we don't risk updates.
I'd rather not introduce new providers (at least to the external API). What would the updating look like? Could we write a test to ensure it wouldn't rerender?
I do think having it on the context would be great btw!
I think it wont cause rerenders since the context will only hold a reference to a Map and that reference will never change.
The provider I propose is internal only, since we don't want to leak the recycler implementation details. For safety, in that provider we could implement shouldComponentUpdate as a function that always return false.
@jbaxleyiii I updated the PR. Current tests are passing and I manually tested it out in my playground and it seems to be working.
If you feel like we need more testing I'd really appreciate some guidance, there are a lot of use cases that I probably miss since I'm not experienced with apollo or react-apollo.
Aug 13, 2017
@jbaxleyiii Thanks for the kind words
I've been thinking and with this implementation the recyclers will be reset when the client changes in the ApolloProvider. I'm not sure how are users using this. Is it common to bounce from client to client in the same application? If this is the case, we may need to keep those recyclers alive as well, and use a Map<ApolloClient, Map<Component, QueryRecycler>> instead to store the state.