NetworkManager
NetworkManager orchestrates asynchronous fetches. By keeping track of all in-flight requests it is able to dedupe identical requests if they are made using the throttle flag.
NetworkManager implements Manager
Lifecycle
Success
Error
Members
constructor({ dataExpiryLength = 60000, errorExpiryLength = 1000 })
Arguments represent the default time (in milliseconds) before a resource is considered 'stale'.
middleware
Drops a response when its fetch started before the last resetEntireStore(). An older response doesn't settle a newer fetch of the same key.
When middleware gets a different controller, a new store uses this NetworkManager, which only happens when the
managers function returns an instance made outside it. NetworkManager stops tracking the old store's fetches, so their promises never settle. It also doesn't send fetches from
the old store.
Consumed Actions
Will initiate network request and then dispatch upon completion.
Processed Actions
Dispatched Actions
cleanup()
Stops nothing. Fetches in flight keep going, and their responses still update the store, because
cleanup() also runs when the store is only hidden, like by <Activity>.
allSettled(): Promise
Resolves once all fetches inflight are complete. Conceptually Promise.allSettled
skipLogging(action)
Used by DevtoolsManager to determine whether to log an action
Default:
skipLogging(action: ActionTypes) {
return action.type === FETCH && action.meta.key in this.fetched;
}
Protected members
handleFetch(fetchAction)
Called when middleware intercepts 'rdc/fetch' action.
Will then start a promise for a key and potentially start the network fetch.
Uses throttle only when instructed by action meta. This is valuable for ensures mutation requests always go through.
handleSet(setAction)
Called when middleware intercepts a set action.
Will resolve the promise associated with set key.
throttle(key, fetch)
Ensures only one request for a given key is in flight at any time
Uses key to either retrieve in-flight promise, or if not create a new promise and call fetch.
getLastReset(): number
Timestamp when entire store was last reset
clear(key)
Stops tracking the fetch for a given key, without settling its promise.
clearAll()
Stops tracking every fetch in flight, without settling their promises.