Skip to content

Commit

Permalink
redux types: Distinguish PerAccountState from GlobalState
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gnprice committed Sep 22, 2021
1 parent 3d98cf9 commit ab805f2
Showing 1 changed file with 45 additions and 26 deletions.
71 changes: 45 additions & 26 deletions src/reduxTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -376,42 +376,29 @@ export type UsersState = $ReadOnlyArray<User>;
* 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,
Expand All @@ -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<PerAccountState>,

// 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
Expand All @@ -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;
}

Expand Down

0 comments on commit ab805f2

Please sign in to comment.