Relay cache with stream pattern?

I would really like to enable the Relay cache in my Flux repository so that I can "travel in time" and get a deep understanding of the application.

It seems like the relay store and actions are all classes that are not serializable, which is a junk. But it looks like I should separate the cache from network requests and store the cache in Flux storage.

Is it interesting or am I barking the wrong tree?

+4
source share
1 answer

Relays can certainly be used with Flux, and we talked with many developers who successfully use them together. The general scheme is to provide Relay with its own server data cache and manage server communications and use Flux to store and update data only for the client.

Reading relay data from a stream

If Flux stores need access to server data, they can use the API Relay.Storeto retrieve data from the server and read from the cache:

// build a query 
var query = Relay.createQuery(Relay.QL`query { ... }`, {var: 'value'});
// fetch any missing data for this query
Relay.Store.primeCache({query}, readyState => {
  if (readyState.done) {
    // read data once the cache is populated
    var data = Relay.Store.readQuery(query)[0];
  }
});

Check Relay Cache

The relay does not support direct debugging support while traveling. However, we are actively working on the developer tools for Relay, and the initial version of this should be available soon. Meanwhile, there are several options for checking the status of the cache:

  • . , RelayStoreData.getDefaultInstance().injectCacheManager(...) ( , API , API- ). CacheManager - , , -, , . , , JSON-. , , .
  • , . , .
+4

Source: https://habr.com/ru/post/1621210/


All Articles