mirror of
https://github.com/mastodon/mastodon.git
synced 2025-11-27 18:10:58 +00:00
add skip dispatch function
This commit is contained in:
parent
54da7ff12b
commit
f2025914e7
|
|
@ -60,7 +60,7 @@ type AppThunk<Arg = void, Returned = void> = (
|
|||
|
||||
type AppThunkCreator<Arg = void, Returned = void, ExtraArg = unknown> = (
|
||||
arg: Arg,
|
||||
api: AppThunkApi,
|
||||
api: AppThunkApi & { skipDispatch: () => void },
|
||||
extra?: ExtraArg,
|
||||
) => Returned;
|
||||
|
||||
|
|
@ -102,11 +102,20 @@ export function createAppThunk<Arg = void, Returned = void, ExtraArg = unknown>(
|
|||
const extra = isDispatcher ? maybeExtra : (maybeCreatorOrExtra as ExtraArg);
|
||||
let action: null | AppThunkActionCreator<Arg, Returned> = null;
|
||||
|
||||
let skipDispatch = false;
|
||||
const toggleSkipDispatch = () => {
|
||||
skipDispatch = !skipDispatch;
|
||||
};
|
||||
|
||||
// Creates a thunk that dispatches the action with the result of the creator.
|
||||
const actionCreator: AppThunk<Arg, Returned> = (arg) => {
|
||||
return (dispatch, getState) => {
|
||||
const result = creator(arg, { dispatch, getState }, extra);
|
||||
if (action) {
|
||||
const result = creator(
|
||||
arg,
|
||||
{ dispatch, getState, skipDispatch: toggleSkipDispatch },
|
||||
extra,
|
||||
);
|
||||
if (action && !skipDispatch) {
|
||||
// Dispatches the action with the result.
|
||||
const actionObj = action(result, arg);
|
||||
dispatch(actionObj);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user