Skip to content

Commit 9b81292

Browse files
gnpricechrisbobbe
andcommitted
redux [nfc]: Set up a GlobalThunkExtras
This doesn't yet do anything, but it provides the vessel through which we can start providing extras here. Co-authored-by: Chris Bobbe <[email protected]>
1 parent ae306ff commit 9b81292

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/boot/store.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import CompressedAsyncStorage from '../storage/CompressedAsyncStorage';
2020
import createMigration from '../redux-persist-migrate/index';
2121
import { getGlobalSession, getGlobalSettings } from '../directSelectors';
2222
import { migrations } from '../storage/migrations';
23+
import type { GlobalThunkExtras } from '../reduxTypes';
2324

2425
if (process.env.NODE_ENV === 'development') {
2526
// Chrome dev tools for Immutable.
@@ -72,14 +73,23 @@ export const cacheKeys: $ReadOnlyArray<$Keys<GlobalState>> = [
7273
'realm', 'streams', 'subscriptions', 'unread', 'userGroups', 'users',
7374
];
7475

75-
const thunkExtras: ThunkExtras = {
76+
const thunkExtras: $Exact<ThunkExtras> = {
7677
// eslint-disable-next-line no-use-before-define
7778
getGlobalSession: () => getGlobalSession(store.getState()),
7879

7980
// eslint-disable-next-line no-use-before-define
8081
getGlobalSettings: () => getGlobalSettings(store.getState()),
8182
};
8283

84+
const globalThunkExtras: $Exact<GlobalThunkExtras> = Object.freeze({
85+
// TODO add things
86+
});
87+
88+
const combinedThunkExtras: ThunkExtras & GlobalThunkExtras = {
89+
...thunkExtras,
90+
...globalThunkExtras,
91+
};
92+
8393
/**
8494
* Return a list of Redux middleware objects to use in our Redux store.
8595
*
@@ -97,7 +107,7 @@ function listMiddleware() {
97107
// Handle the fancy "thunk" actions we often use, i.e. async
98108
// functions of `dispatch` and `state`. See docs:
99109
// https://github.com/reduxjs/redux-thunk
100-
thunkMiddleware.withExtraArgument(thunkExtras),
110+
thunkMiddleware.withExtraArgument(combinedThunkExtras),
101111
];
102112

103113
if (config.enableReduxLogging) {

src/reduxTypes.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -636,21 +636,26 @@ export interface Dispatch {
636636
/** A per-account thunk action returning T. */
637637
export type ThunkAction<T> = (Dispatch, () => PerAccountState, ThunkExtras) => T;
638638

639+
/** The extras object passed to a global thunk action. */
640+
export type GlobalThunkExtras = $ReadOnly<{
641+
// TODO add things
642+
...
643+
}>;
644+
639645
/** The Redux `dispatch` for a global context. */
640646
export interface GlobalDispatch {
641647
<A: DispatchableWithoutAccountAction>(action: A): A;
642648
<T>(GlobalThunkAction<T>): T;
643649
}
644650

645651
/** A global thunk action returning T. */
646-
// This might take some extras later (e.g., to do something per-account on a
647-
// specific account), but for now it needs none.
648-
export type GlobalThunkAction<T> = (GlobalDispatch, () => GlobalState) => T;
652+
export type GlobalThunkAction<T> = (GlobalDispatch, () => GlobalState, GlobalThunkExtras) => T;
649653

650654
// The two pairs of dispatch/thunk-action types aren't interchangeable,
651655
// in either direction.
652656
// $FlowExpectedError[incompatible-return]
653657
(d: GlobalDispatch): Dispatch => d;
658+
// $FlowExpectedError[prop-missing]
654659
// $FlowExpectedError[incompatible-return]
655660
<T>(a: ThunkAction<T>): GlobalThunkAction<T> => a;
656661
// $FlowExpectedError[incompatible-return]

0 commit comments

Comments
 (0)