Skip to main content
Version: 7.3

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.

implements

NetworkManager implements Manager

Members

constructor(dataExpiryLength = 60000, errorExpiryLength = 1000)

Arguments represent the default time (in miliseconds) before a resource is considered 'stale'.

middleware

Consumed Actions

Will initiate network request and then dispatch upon completion.

Processed Actions

Dispatched Actions

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_TYPE && action.meta.key in this.fetched;
}

Protected members

handleFetch(fetchAction)

Called when middleware intercepts 'rest-hooks/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.

handleReceive(receiveAction)

Called when middleware intercepts a receive action.

Will resolve the promise associated with receive 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)

Clear promise state for a given key

clearAll()

Ensures all promises are completed by rejecting remaining