@@ -20,6 +20,7 @@ import CompressedAsyncStorage from '../storage/CompressedAsyncStorage';
2020import createMigration from '../redux-persist-migrate/index' ;
2121import { getGlobalSession , getGlobalSettings } from '../directSelectors' ;
2222import { migrations } from '../storage/migrations' ;
23+ import type { Dispatch , GlobalThunkExtras } from '../reduxTypes' ;
2324
2425if ( process . env . NODE_ENV === 'development' ) {
2526 // Chrome dev tools for Immutable.
@@ -72,14 +73,35 @@ export const cacheKeys: $ReadOnlyArray<$Keys<GlobalState>> = [
7273 'realm' , 'streams' , 'subscriptions' , 'unread' , 'userGroups' , 'users' ,
7374] ;
7475
75- const thunkExtras : ThunkExtras = {
76- // eslint-disable-next-line no-use-before-define
77- getGlobalSession : ( ) => getGlobalSession ( store . getState ( ) ) ,
76+ /* eslint-disable no-use-before-define */
7877
79- // eslint-disable-next-line no-use-before-define
78+ const thunkExtras : $Exact < ThunkExtras > = {
79+ getGlobalSession : ( ) = > getGlobalSession ( store . getState ( ) ) ,
8080 getGlobalSettings : ( ) => getGlobalSettings ( store . getState ( ) ) ,
8181} ;
8282
83+ const globalThunkExtras: $Exact< GlobalThunkExtras > = {
84+ // $FlowFixMe[escaped-generic]
85+ // $FlowFixMe[incompatible-type]
86+ /* $FlowFixMe[incompatible-cast]
87+ The `store` type isn't complete: in particular it ignores thunk actions.
88+
89+ We're also using here the fact that the one function `store.dispatch`
90+ secretly plays both the role of our `GlobalDispatch` type and our
91+ `Dispatch` type... and that in the latter role, the PerAccountState
92+ that it acts on is the one belonging to the active account.
93+
94+ TODO(#5006): We'll have to add more logic here when per-account and
95+ global state become distinct.
96+ */
97+ activeAccountDispatch : action => ( store . dispatch : Dispatch ) ( action ) ,
98+ } ;
99+
100+ const combinedThunkExtras: ThunkExtras & GlobalThunkExtras = {
101+ ...thunkExtras ,
102+ ...globalThunkExtras ,
103+ } ;
104+
83105/**
84106 * Return a list of Redux middleware objects to use in our Redux store.
85107 *
@@ -97,7 +119,7 @@ function listMiddleware() {
97119 // Handle the fancy "thunk" actions we often use, i.e. async
98120 // functions of `dispatch` and `state`. See docs:
99121 // https://github.com/reduxjs/redux-thunk
100- thunkMiddleware . withExtraArgument ( thunkExtras ) ,
122+ thunkMiddleware . withExtraArgument ( combinedThunkExtras ) ,
101123 ] ;
102124
103125 if ( config . enableReduxLogging ) {
0 commit comments