Skip to content

Commit ab805f2

Browse files
committed
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.
1 parent 3d98cf9 commit ab805f2

File tree

1 file changed

+45
-26
lines changed

1 file changed

+45
-26
lines changed

src/reduxTypes.js

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import type {
2727
UserPresence,
2828
UserStatusMapObject,
2929
} from './api/apiTypes';
30-
import type { SessionState } from './session/sessionReducer';
30+
import type { PerAccountSessionState, SessionState } from './session/sessionReducer';
3131
import type { PmConversationsState } from './pm-conversations/pmConversationsModel';
3232
import type { UnreadState } from './unread/unreadModelTypes';
3333

@@ -376,42 +376,29 @@ export type UsersState = $ReadOnlyArray<User>;
376376
* parts of our code will in that future operate on a particular account and
377377
* which parts will operate on all accounts' data or none.
378378
*/
379-
// And *initially* initially, the type literally just is GlobalState.
380-
// That'll change in just a few commits, though.
381-
export type PerAccountState = GlobalState;
379+
export type PerAccountState = $ReadOnly<{
380+
// TODO accounts
382381

383-
/**
384-
* Our complete Redux state tree.
385-
*
386-
* Each property is a subtree maintained by its own reducer function. These
387-
* are named in a regular pattern; see also `src/boot/reducers.js`.
388-
*
389-
* We use `redux-persist` to write parts of this state tree to persistent
390-
* device storage that survives when the app is closed, and to read it back
391-
* ("rehydrate" it) from that storage at launch time. See `src/boot/store.js`.
392-
* Other parts of the state tree are not persisted.
393-
*
394-
* See in particular `discardKeys`, `storeKeys`, and `cacheKeys`, which
395-
* identify which subtrees are persisted and which are not.
396-
*/
397-
export type GlobalState = $ReadOnly<{|
398-
accounts: AccountsState,
382+
// Jumbles of per-account state and client state.
383+
session: PerAccountSessionState,
384+
settings: PerAccountSettingsState,
385+
386+
// Per-account state that's *not* from the server.
387+
drafts: DraftsState,
388+
outbox: OutboxState,
389+
390+
// Per-account state: server data for the active account.
399391
alertWords: AlertWordsState,
400392
caughtUp: CaughtUpState,
401-
drafts: DraftsState,
402393
fetching: FetchingState,
403394
flags: FlagsState,
404395
messages: MessagesState,
405-
migrations: MigrationsState,
406396
mute: MuteState,
407397
mutedUsers: MutedUsersState,
408398
narrows: NarrowsState,
409-
outbox: OutboxState,
410399
pmConversations: PmConversationsState,
411400
presence: PresenceState,
412401
realm: RealmState,
413-
session: SessionState,
414-
settings: SettingsState,
415402
streams: StreamsState,
416403
subscriptions: SubscriptionsState,
417404
topics: TopicsState,
@@ -420,6 +407,37 @@ export type GlobalState = $ReadOnly<{|
420407
userGroups: UserGroupsState,
421408
userStatus: UserStatusState,
422409
users: UsersState,
410+
411+
...
412+
}>;
413+
414+
/**
415+
* Our complete Redux state tree.
416+
*
417+
* Each property is a subtree maintained by its own reducer function. These
418+
* are named in a regular pattern; see also `src/boot/reducers.js`.
419+
*
420+
* We use `redux-persist` to write parts of this state tree to persistent
421+
* device storage that survives when the app is closed, and to read it back
422+
* ("rehydrate" it) from that storage at launch time. See `src/boot/store.js`.
423+
* Other parts of the state tree are not persisted.
424+
*
425+
* See in particular `discardKeys`, `storeKeys`, and `cacheKeys`, which
426+
* identify which subtrees are persisted and which are not.
427+
*/
428+
export type GlobalState = $ReadOnly<{|
429+
...$Exact<PerAccountState>,
430+
431+
// Metadata for the global state, as persisted on disk.
432+
migrations: MigrationsState,
433+
434+
// Jumbles of per-account state and client state.
435+
session: SessionState,
436+
settings: SettingsState,
437+
438+
// Per-account state but for all accounts together.
439+
// Mix of server data and otherwise.
440+
accounts: AccountsState,
423441
|}>;
424442

425443
// For now, under our single-active-account model, we want a GlobalState
@@ -436,7 +454,8 @@ export type GlobalState = $ReadOnly<{|
436454
* TODO(#5006): We'll have to fix and eliminate each call to this.
437455
*/
438456
export function assumeSecretlyGlobalState(state: PerAccountState): GlobalState {
439-
// For *right* now, this doesn't even have a fixme, because the types alias.
457+
// $FlowFixMe[incompatible-exact]
458+
// $FlowFixMe[prop-missing]
440459
return state;
441460
}
442461

0 commit comments

Comments
 (0)