From ab805f2b2ec63b02a610ae9008b859577f9a15db Mon Sep 17 00:00:00 2001 From: Greg Price Date: Mon, 20 Sep 2021 10:36:42 -0700 Subject: [PATCH] redux types: Distinguish PerAccountState from GlobalState Now the fact that Flow still passes means that we don't have any place where we have a PerAccountState, and try to pass it off (without an explicit assumeSecretlyGlobalState, that is) as a GlobalState. --- src/reduxTypes.js | 71 ++++++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 26 deletions(-) diff --git a/src/reduxTypes.js b/src/reduxTypes.js index df06c399aaf..cd470b2116e 100644 --- a/src/reduxTypes.js +++ b/src/reduxTypes.js @@ -27,7 +27,7 @@ import type { UserPresence, UserStatusMapObject, } from './api/apiTypes'; -import type { SessionState } from './session/sessionReducer'; +import type { PerAccountSessionState, SessionState } from './session/sessionReducer'; import type { PmConversationsState } from './pm-conversations/pmConversationsModel'; import type { UnreadState } from './unread/unreadModelTypes'; @@ -376,42 +376,29 @@ export type UsersState = $ReadOnlyArray; * parts of our code will in that future operate on a particular account and * which parts will operate on all accounts' data or none. */ -// And *initially* initially, the type literally just is GlobalState. -// That'll change in just a few commits, though. -export type PerAccountState = GlobalState; +export type PerAccountState = $ReadOnly<{ + // TODO accounts -/** - * Our complete Redux state tree. - * - * Each property is a subtree maintained by its own reducer function. These - * are named in a regular pattern; see also `src/boot/reducers.js`. - * - * We use `redux-persist` to write parts of this state tree to persistent - * device storage that survives when the app is closed, and to read it back - * ("rehydrate" it) from that storage at launch time. See `src/boot/store.js`. - * Other parts of the state tree are not persisted. - * - * See in particular `discardKeys`, `storeKeys`, and `cacheKeys`, which - * identify which subtrees are persisted and which are not. - */ -export type GlobalState = $ReadOnly<{| - accounts: AccountsState, + // Jumbles of per-account state and client state. + session: PerAccountSessionState, + settings: PerAccountSettingsState, + + // Per-account state that's *not* from the server. + drafts: DraftsState, + outbox: OutboxState, + + // Per-account state: server data for the active account. alertWords: AlertWordsState, caughtUp: CaughtUpState, - drafts: DraftsState, fetching: FetchingState, flags: FlagsState, messages: MessagesState, - migrations: MigrationsState, mute: MuteState, mutedUsers: MutedUsersState, narrows: NarrowsState, - outbox: OutboxState, pmConversations: PmConversationsState, presence: PresenceState, realm: RealmState, - session: SessionState, - settings: SettingsState, streams: StreamsState, subscriptions: SubscriptionsState, topics: TopicsState, @@ -420,6 +407,37 @@ export type GlobalState = $ReadOnly<{| userGroups: UserGroupsState, userStatus: UserStatusState, users: UsersState, + + ... +}>; + +/** + * Our complete Redux state tree. + * + * Each property is a subtree maintained by its own reducer function. These + * are named in a regular pattern; see also `src/boot/reducers.js`. + * + * We use `redux-persist` to write parts of this state tree to persistent + * device storage that survives when the app is closed, and to read it back + * ("rehydrate" it) from that storage at launch time. See `src/boot/store.js`. + * Other parts of the state tree are not persisted. + * + * See in particular `discardKeys`, `storeKeys`, and `cacheKeys`, which + * identify which subtrees are persisted and which are not. + */ +export type GlobalState = $ReadOnly<{| + ...$Exact, + + // Metadata for the global state, as persisted on disk. + migrations: MigrationsState, + + // Jumbles of per-account state and client state. + session: SessionState, + settings: SettingsState, + + // Per-account state but for all accounts together. + // Mix of server data and otherwise. + accounts: AccountsState, |}>; // For now, under our single-active-account model, we want a GlobalState @@ -436,7 +454,8 @@ export type GlobalState = $ReadOnly<{| * TODO(#5006): We'll have to fix and eliminate each call to this. */ export function assumeSecretlyGlobalState(state: PerAccountState): GlobalState { - // For *right* now, this doesn't even have a fixme, because the types alias. + // $FlowFixMe[incompatible-exact] + // $FlowFixMe[prop-missing] return state; }