Skip to content

Commit

Permalink
redux types: Add two assumeSecretlyGlobalState markings
Browse files Browse the repository at this point in the history
In a bit, we'll make PerAccountState and GlobalState actually be
distinct, and we'll mark most of our selectors as per-account or
global accordingly.

The major area of selectors we'll skip at first, because it requires
some careful sorting-out of what its callers expect of it, is the
selectors on `state.accounts` found in `accountsSelectors`.  We'll
initially say those are global selectors, reflecting the data that
(like all our selectors) they have access to now in the status quo.

Because we'll have GlobalState freely implicitly convert to
PerAccountState (for a while) but not vice versa, that means that
Flow will notice any place that a per-account selector (which has
only a PerAccountState) invokes one of those selectors (which demands
a GlobalState).  We don't have many of those, but we have these two.

In each of these cases, the calling selector really is working on
a particular account's data, and although the data it's getting from
the callee selector is stored in `state.accounts`, it really is
specific to the active account; and in a multi-account future, the
data we'll want here is really from whatever account the caller is
working on, regardless of whether it's the active account in the UI.
So these selectors are perfectly well doing the right thing; we just
need to add these assumeSecretlyGlobalState markings, to tell Flow
that we know about the type mismatch here and we're on it.
  • Loading branch information
gnprice committed Sep 22, 2021
1 parent 4c0b7ee commit b33f278
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/emoji/emojiSelectors.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/* @flow strict-local */
import { createSelector } from 'reselect';
import type { Selector, RealmEmojiById, ImageEmojiType } from '../types';
import { assumeSecretlyGlobalState } from '../reduxTypes';
import { getRawRealmEmoji } from '../directSelectors';
import { getIdentity } from '../account/accountsSelectors';
import zulipExtraEmojiMap from './zulipExtraEmojiMap';
import { objectFromEntries } from '../jsBackport';

export const getAllImageEmojiById: Selector<RealmEmojiById> = createSelector(
getIdentity,
state => getIdentity(assumeSecretlyGlobalState(state)),
getRawRealmEmoji,
(identity, realmEmoji) => {
const result: {| [string]: ImageEmojiType |} = {};
Expand Down
3 changes: 2 additions & 1 deletion src/pm-conversations/pmConversationsSelectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import invariant from 'invariant';
import { createSelector } from 'reselect';

import type { GlobalState, Message, PmConversationData, Selector } from '../types';
import { assumeSecretlyGlobalState } from '../reduxTypes';
import { getPrivateMessages } from '../message/messageSelectors';
import { getAllUsersById, getOwnUserId } from '../users/userSelectors';
import { getUnreadByPms, getUnreadByHuddles } from '../unread/unreadSelectors';
Expand Down Expand Up @@ -121,7 +122,7 @@ function getRecentConversationsModernImpl(
}

const getServerIsOld: Selector<boolean> = createSelector(
getServerVersion,
state => getServerVersion(assumeSecretlyGlobalState(state)),
version => !(version && version.isAtLeast(model.MIN_RECENTPMS_SERVER_VERSION)),
);

Expand Down

0 comments on commit b33f278

Please sign in to comment.