Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
Add shouldDequeueSelector option to network middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
melvynhills committed Jul 8, 2019
1 parent 8851c62 commit fa1b7ff
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/redux/createNetworkMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ function createNetworkMiddleware({
regexActionType = /FETCH.*REQUEST/,
actionTypes = [],
queueReleaseThrottle = 50,
shouldDequeueSelector = null,
}: Arguments = {}) {
return ({ getState }: MiddlewareAPI<State>) => (
next: (action: any) => void,
Expand All @@ -114,7 +115,16 @@ function createNetworkMiddleware({
}

const isBackOnline = didComeBackOnline(action, isConnected);
if (isBackOnline) {
let shouldDequeue = false;
if (shouldDequeueSelector) {
shouldDequeue =
(isConnected || isBackOnline) &&
actionQueue.length > 0 &&
shouldDequeueSelector(getState());
} else {
shouldDequeue = isBackOnline;
}
if (shouldDequeue) {
// Dispatching queued actions in order of arrival (if we have any)
next(action);
return releaseQueue(actionQueue);
Expand Down

0 comments on commit fa1b7ff

Please sign in to comment.