Skip to content

Commit

Permalink
outboxActions [nfc]: Make trySendMessages a thunk action creator.
Browse files Browse the repository at this point in the history
It'll be easier to write a test for it, when we eventually attempt
that, probably pending resolution of zulip#3881. In particular, without
this change, Flow would complain if we tried to pass
`store.dispatch` -- where `store` is mocked using redux-mock-store
-- as the first argument, for which our custom `Dispatch` type is
expected. I suspect this could be fixed by tightening up the
redux-mock-store libdef's `Dispatch` type. But, for consistency's
sake, `trySendMessages` should probably be a thunk action creator in
any case.

In e5268bb (and confirmed again with logging just now), we
observed that the return value of our function (in this case a
boolean) will be passed through and returned by the `dispatch` call.
  • Loading branch information
chrisbobbe committed Dec 7, 2020
1 parent 9e8408c commit 65d9ae8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/outbox/outboxActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const messageSendComplete = (localMessageId: number): Action => ({
local_message_id: localMessageId,
});

export const trySendMessages = (dispatch: Dispatch, getState: GetState): boolean => {
export const trySendMessages = () => (dispatch: Dispatch, getState: GetState): boolean => {
const state = getState();
const auth = getAuth(state);
const outboxToSend = state.outbox.filter(outbox => !outbox.isSent);
Expand Down Expand Up @@ -119,7 +119,7 @@ export const sendOutbox = () => async (dispatch: Dispatch, getState: GetState) =
}
dispatch(toggleOutboxSending(true));
const backoffMachine = new BackoffMachine();
while (!trySendMessages(dispatch, getState)) {
while (!dispatch(trySendMessages())) {
await backoffMachine.wait();
}
dispatch(toggleOutboxSending(false));
Expand Down

0 comments on commit 65d9ae8

Please sign in to comment.