Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How about retain prop? (easy & cheap Relay Classic caching behaviour) #5

Closed
adjourn opened this issue Aug 14, 2017 · 2 comments
Closed

Comments

@adjourn
Copy link

adjourn commented Aug 14, 2017

Would it make sense to implement a prop to disable GC (a'la Relay Classic behaviour) to this package?

I find it wasteful, even annoying to fetch all the data again & again in most of my own apps. Very few (browser) apps are very long-lived & I don't belive most of our apps ever get memory problems, especially if you don't target emerging markets (very low-end devices).

It would also be pleasantly flexible for different strategies, for example:

  • List view - dynamic, updates often, don't retain: <QueryRenderer other={"props"}/>
  • Single item view - retain it: <QueryRenderer retain other={"props"}/>

It would be very cheap because it would only be checked againts on componentWillUnmount or what?


But how would one even implement this? I think something like this, haven't seen any side-effects so far..

_release() {
  // ... _rootSubscription & _pendingFetch code -> nothing to do with retaining data

  // reference to retained data ("protected" from garbage collection) - jackpot, add condition
  if (!this.props.retain && this._selectionReference) {
    this._selectionReference.dispose();
    this._selectionReference = null;
  }
}

I haven't 100% figured out yet how onError & onNext might affect retained data in different situations.

@robrichard
Copy link
Member

@unirey sounds good to me. Do you mind opening a PR?

@robrichard
Copy link
Member

I added the retain prop in the latest version 2.0.1. Please let me know if this works for your use case!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants