Skip to content

Commit

Permalink
[lib] Replace BaseAppState<*> with default type param
Browse files Browse the repository at this point in the history
Summary:
`*` is basically `any` in modern versions of Flow. This diff removes most of the uses of `*` in our codebase.

This came up in D8526 and D8644.

Depends on D8685

Test Plan: Flow

Reviewers: inka, michal, patryk

Reviewed By: patryk

Subscribers: tomek

Differential Revision: https://phab.comm.dev/D8686
  • Loading branch information
Ashoat committed Aug 1, 2023
1 parent 76af95c commit c451a81
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 91 deletions.
16 changes: 8 additions & 8 deletions lib/selectors/calendar-filter-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ function filteredThreadIDs(
}

const filteredThreadIDsSelector: (
state: BaseAppState<*>,
state: BaseAppState<>,
) => ?$ReadOnlySet<string> = createSelector(
(state: BaseAppState<*>) => state.calendarFilters,
(state: BaseAppState<>) => state.calendarFilters,
filteredThreadIDs,
);

Expand All @@ -53,9 +53,9 @@ function nonThreadCalendarFilters(
}

const nonThreadCalendarFiltersSelector: (
state: BaseAppState<*>,
state: BaseAppState<>,
) => $ReadOnlyArray<CalendarFilter> = createSelector(
(state: BaseAppState<*>) => state.calendarFilters,
(state: BaseAppState<>) => state.calendarFilters,
nonThreadCalendarFilters,
);

Expand All @@ -66,9 +66,9 @@ function nonExcludeDeletedCalendarFilters(
}

const nonExcludeDeletedCalendarFiltersSelector: (
state: BaseAppState<*>,
state: BaseAppState<>,
) => $ReadOnlyArray<CalendarFilter> = createSelector(
(state: BaseAppState<*>) => state.calendarFilters,
(state: BaseAppState<>) => state.calendarFilters,
nonExcludeDeletedCalendarFilters,
);

Expand All @@ -84,9 +84,9 @@ function filterExists(
return false;
}

const includeDeletedSelector: (state: BaseAppState<*>) => boolean =
const includeDeletedSelector: (state: BaseAppState<>) => boolean =
createSelector(
(state: BaseAppState<*>) => state.calendarFilters,
(state: BaseAppState<>) => state.calendarFilters,
(calendarFilters: $ReadOnlyArray<CalendarFilter>) =>
!filterExists(calendarFilters, calendarThreadFilterTypes.NOT_DELETED),
);
Expand Down
19 changes: 9 additions & 10 deletions lib/selectors/chat-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ export type ChatThreadItem = {
+pendingPersonalThreadUserInfo?: UserInfo,
};

const messageInfoSelector: (state: BaseAppState<*>) => {
const messageInfoSelector: (state: BaseAppState<>) => {
+[id: string]: ?MessageInfo,
} = createObjectSelector(
(state: BaseAppState<*>) => state.messageStore.messages,
(state: BaseAppState<*>) => state.currentUserInfo && state.currentUserInfo.id,
(state: BaseAppState<*>) => state.userStore.userInfos,
(state: BaseAppState<>) => state.messageStore.messages,
(state: BaseAppState<>) => state.currentUserInfo && state.currentUserInfo.id,
(state: BaseAppState<>) => state.userStore.userInfos,
threadInfoSelector,
createMessageInfo,
);
Expand Down Expand Up @@ -201,10 +201,10 @@ function createChatThreadItem(
};
}

const chatListData: (state: BaseAppState<*>) => $ReadOnlyArray<ChatThreadItem> =
const chatListData: (state: BaseAppState<>) => $ReadOnlyArray<ChatThreadItem> =
createSelector(
threadInfoSelector,
(state: BaseAppState<*>) => state.messageStore,
(state: BaseAppState<>) => state.messageStore,
messageInfoSelector,
sidebarInfoSelector,
(
Expand Down Expand Up @@ -565,11 +565,11 @@ const baseMessageListData = (
additionalMessages: $ReadOnlyArray<MessageInfo>,
) =>
createSelector(
(state: BaseAppState<*>) => state.messageStore,
(state: BaseAppState<>) => state.messageStore,
messageInfoSelector,
threadInfoSelector,
threadInfoFromSourceMessageIDSelector,
(state: BaseAppState<*>) =>
(state: BaseAppState<>) =>
state.currentUserInfo && state.currentUserInfo.id,
(
messageStore: MessageStore,
Expand All @@ -596,8 +596,7 @@ type MessageListData = ?(ChatMessageItem[]);
const messageListData: (
threadID: ?string,
additionalMessages: $ReadOnlyArray<MessageInfo>,
) => (state: BaseAppState<*>) => MessageListData =
memoize2(baseMessageListData);
) => (state: BaseAppState<>) => MessageListData = memoize2(baseMessageListData);

export type UseMessageListDataArgs = {
+searching: boolean,
Expand Down
10 changes: 5 additions & 5 deletions lib/selectors/loading-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ function getTrackingKey(
const baseCreateLoadingStatusSelector = (
actionTypes: ActionTypes<*, *, *>,
overrideKey?: string,
): ((state: BaseAppState<*>) => LoadingStatus) => {
): ((state: BaseAppState<>) => LoadingStatus) => {
// This makes sure that reduceLoadingStatuses tracks this action
registerFetchKey(actionTypes);
const trackingKey = getTrackingKey(actionTypes, overrideKey);
return createSelector(
(state: BaseAppState<*>) => state.loadingStatuses[trackingKey],
(state: BaseAppState<>) => state.loadingStatuses[trackingKey],
(loadingStatusInfo: { [idx: number]: LoadingStatus }) =>
loadingStatusFromInfo(loadingStatusInfo),
);
Expand All @@ -57,7 +57,7 @@ const baseCreateLoadingStatusSelector = (
const createLoadingStatusSelector: (
actionTypes: ActionTypes<*, *, *>,
overrideKey?: string,
) => (state: BaseAppState<*>) => LoadingStatus = _memoize(
) => (state: BaseAppState<>) => LoadingStatus = _memoize(
baseCreateLoadingStatusSelector,
getTrackingKey,
);
Expand All @@ -77,9 +77,9 @@ function combineLoadingStatuses(
return errorExists ? 'error' : 'inactive';
}

const globalLoadingStatusSelector: (state: BaseAppState<*>) => LoadingStatus =
const globalLoadingStatusSelector: (state: BaseAppState<>) => LoadingStatus =
createSelector(
(state: BaseAppState<*>) => state.loadingStatuses,
(state: BaseAppState<>) => state.loadingStatuses,
(loadingStatusInfos: {
[key: string]: { [idx: number]: LoadingStatus },
}): LoadingStatus => {
Expand Down
2 changes: 1 addition & 1 deletion lib/selectors/local-id-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function numberFromLocalID(localID: string): number {
return parseInt(matches[1], 10);
}

function highestLocalIDSelector(state: ?BaseAppState<*>): number {
function highestLocalIDSelector(state: ?BaseAppState<>): number {
let highestLocalIDFound = -1;

if (state && state.messageStore) {
Expand Down
8 changes: 4 additions & 4 deletions lib/selectors/nav-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ function calendarRangeExpired(lastUserInteractionCalendar: number): boolean {
}

const currentCalendarQuery: (
state: BaseAppState<*>,
state: BaseAppState<>,
) => (calendarActive: boolean) => CalendarQuery = createSelector(
(state: BaseAppState<*>) => state.entryStore.lastUserInteractionCalendar,
(state: BaseAppState<*>) => state.navInfo,
(state: BaseAppState<*>) => state.calendarFilters,
(state: BaseAppState<>) => state.entryStore.lastUserInteractionCalendar,
(state: BaseAppState<>) => state.navInfo,
(state: BaseAppState<>) => state.calendarFilters,
(
lastUserInteractionCalendar: number,
navInfo: BaseNavInfo,
Expand Down
4 changes: 2 additions & 2 deletions lib/selectors/relationship-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import {
} from '../types/relationship-types.js';
import type { UserInfos } from '../types/user-types.js';

const userRelationshipsSelector: (state: BaseAppState<*>) => UserRelationships =
const userRelationshipsSelector: (state: BaseAppState<>) => UserRelationships =
createSelector(
(state: BaseAppState<*>) => state.userStore.userInfos,
(state: BaseAppState<>) => state.userStore.userInfos,
(userInfos: UserInfos) => {
const unorderedFriendRequests = [];
const unorderedFriends = [];
Expand Down
84 changes: 41 additions & 43 deletions lib/selectors/thread-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ import { values } from '../utils/objects.js';

const _mapValuesWithKeys = _mapValues.convert({ cap: false });

type ThreadInfoSelectorType = (state: BaseAppState<*>) => {
type ThreadInfoSelectorType = (state: BaseAppState<>) => {
+[id: string]: ThreadInfo,
};
const threadInfoSelector: ThreadInfoSelectorType = createObjectSelector(
(state: BaseAppState<*>) => state.threadStore.threadInfos,
(state: BaseAppState<*>) => state.currentUserInfo && state.currentUserInfo.id,
(state: BaseAppState<*>) => state.userStore.userInfos,
(state: BaseAppState<>) => state.threadStore.threadInfos,
(state: BaseAppState<>) => state.currentUserInfo && state.currentUserInfo.id,
(state: BaseAppState<>) => state.userStore.userInfos,
threadInfoFromRawThreadInfo,
);

const communityThreadSelector: (
state: BaseAppState<*>,
state: BaseAppState<>,
) => $ReadOnlyArray<ThreadInfo> = createSelector(
threadInfoSelector,
(threadInfos: { +[id: string]: ThreadInfo }) => {
Expand All @@ -83,7 +83,7 @@ const communityThreadSelector: (
);

const canBeOnScreenThreadInfos: (
state: BaseAppState<*>,
state: BaseAppState<>,
) => $ReadOnlyArray<ThreadInfo> = createSelector(
threadInfoSelector,
(threadInfos: { +[id: string]: ThreadInfo }) => {
Expand All @@ -100,7 +100,7 @@ const canBeOnScreenThreadInfos: (
);

const onScreenThreadInfos: (
state: BaseAppState<*>,
state: BaseAppState<>,
) => $ReadOnlyArray<ThreadInfo> = createSelector(
filteredThreadIDsSelector,
canBeOnScreenThreadInfos,
Expand All @@ -117,7 +117,7 @@ const onScreenThreadInfos: (
);

const onScreenEntryEditableThreadInfos: (
state: BaseAppState<*>,
state: BaseAppState<>,
) => $ReadOnlyArray<ThreadInfo> = createSelector(
onScreenThreadInfos,
(threadInfos: $ReadOnlyArray<ThreadInfo>) =>
Expand All @@ -126,24 +126,24 @@ const onScreenEntryEditableThreadInfos: (
),
);

const entryInfoSelector: (state: BaseAppState<*>) => {
const entryInfoSelector: (state: BaseAppState<>) => {
+[id: string]: EntryInfo,
} = createObjectSelector(
(state: BaseAppState<*>) => state.entryStore.entryInfos,
(state: BaseAppState<*>) => state.currentUserInfo && state.currentUserInfo.id,
(state: BaseAppState<*>) => state.userStore.userInfos,
(state: BaseAppState<>) => state.entryStore.entryInfos,
(state: BaseAppState<>) => state.currentUserInfo && state.currentUserInfo.id,
(state: BaseAppState<>) => state.userStore.userInfos,
createEntryInfo,
);

// "current" means within startDate/endDate range, not deleted, and in
// onScreenThreadInfos
const currentDaysToEntries: (state: BaseAppState<*>) => {
const currentDaysToEntries: (state: BaseAppState<>) => {
+[dayString: string]: EntryInfo[],
} = createSelector(
entryInfoSelector,
(state: BaseAppState<*>) => state.entryStore.daysToEntries,
(state: BaseAppState<*>) => state.navInfo.startDate,
(state: BaseAppState<*>) => state.navInfo.endDate,
(state: BaseAppState<>) => state.entryStore.daysToEntries,
(state: BaseAppState<>) => state.navInfo.startDate,
(state: BaseAppState<>) => state.navInfo.endDate,
onScreenThreadInfos,
includeDeletedSelector,
(
Expand Down Expand Up @@ -179,7 +179,7 @@ const currentDaysToEntries: (state: BaseAppState<*>) => {
},
);

const childThreadInfos: (state: BaseAppState<*>) => {
const childThreadInfos: (state: BaseAppState<>) => {
+[id: string]: $ReadOnlyArray<ThreadInfo>,
} = createSelector(
threadInfoSelector,
Expand Down Expand Up @@ -214,11 +214,11 @@ function getMostRecentRawMessageInfo(
return null;
}

const sidebarInfoSelector: (state: BaseAppState<*>) => {
const sidebarInfoSelector: (state: BaseAppState<>) => {
+[id: string]: $ReadOnlyArray<SidebarInfo>,
} = createObjectSelector(
childThreadInfos,
(state: BaseAppState<*>) => state.messageStore,
(state: BaseAppState<>) => state.messageStore,
(childThreads: $ReadOnlyArray<ThreadInfo>, messageStore: MessageStore) => {
const sidebarInfos = [];
for (const childThreadInfo of childThreads) {
Expand Down Expand Up @@ -248,29 +248,27 @@ const sidebarInfoSelector: (state: BaseAppState<*>) => {
},
);

const unreadCount: (state: BaseAppState<*>) => number = createSelector(
(state: BaseAppState<*>) => state.threadStore.threadInfos,
const unreadCount: (state: BaseAppState<>) => number = createSelector(
(state: BaseAppState<>) => state.threadStore.threadInfos,
(threadInfos: { +[id: string]: RawThreadInfo }): number =>
values(threadInfos).filter(
threadInfo =>
threadInHomeChatList(threadInfo) && threadInfo.currentUser.unread,
).length,
);

const unreadBackgroundCount: (state: BaseAppState<*>) => number =
createSelector(
(state: BaseAppState<*>) => state.threadStore.threadInfos,
(threadInfos: { +[id: string]: RawThreadInfo }): number =>
values(threadInfos).filter(
threadInfo =>
threadInBackgroundChatList(threadInfo) &&
threadInfo.currentUser.unread,
).length,
);
const unreadBackgroundCount: (state: BaseAppState<>) => number = createSelector(
(state: BaseAppState<>) => state.threadStore.threadInfos,
(threadInfos: { +[id: string]: RawThreadInfo }): number =>
values(threadInfos).filter(
threadInfo =>
threadInBackgroundChatList(threadInfo) && threadInfo.currentUser.unread,
).length,
);

const baseAncestorThreadInfos = (threadID: string) =>
createSelector(
(state: BaseAppState<*>) => threadInfoSelector(state),
(state: BaseAppState<>) => threadInfoSelector(state),
(threadInfos: {
+[id: string]: ThreadInfo,
}): $ReadOnlyArray<ThreadInfo> => {
Expand All @@ -287,13 +285,13 @@ const baseAncestorThreadInfos = (threadID: string) =>

const ancestorThreadInfos: (
threadID: string,
) => (state: BaseAppState<*>) => $ReadOnlyArray<ThreadInfo> = _memoize(
) => (state: BaseAppState<>) => $ReadOnlyArray<ThreadInfo> = _memoize(
baseAncestorThreadInfos,
);

const baseOtherUsersButNoOtherAdmins = (threadID: string) =>
createSelector(
(state: BaseAppState<*>) => state.threadStore.threadInfos[threadID],
(state: BaseAppState<>) => state.threadStore.threadInfos[threadID],
relativeMemberInfoSelectorForMembersOfThread(threadID),
(
threadInfo: ?RawThreadInfo,
Expand Down Expand Up @@ -324,7 +322,7 @@ const baseOtherUsersButNoOtherAdmins = (threadID: string) =>

const otherUsersButNoOtherAdmins: (
threadID: string,
) => (state: BaseAppState<*>) => boolean = _memoize(
) => (state: BaseAppState<>) => boolean = _memoize(
baseOtherUsersButNoOtherAdmins,
);

Expand Down Expand Up @@ -359,17 +357,17 @@ function mostRecentlyReadThread(
return mostRecent ? mostRecent.threadID : null;
}

const mostRecentlyReadThreadSelector: (state: BaseAppState<*>) => ?string =
const mostRecentlyReadThreadSelector: (state: BaseAppState<>) => ?string =
createSelector(
(state: BaseAppState<*>) => state.messageStore,
(state: BaseAppState<*>) => state.threadStore.threadInfos,
(state: BaseAppState<>) => state.messageStore,
(state: BaseAppState<>) => state.threadStore.threadInfos,
mostRecentlyReadThread,
);

const threadInfoFromSourceMessageIDSelector: (state: BaseAppState<*>) => {
const threadInfoFromSourceMessageIDSelector: (state: BaseAppState<>) => {
+[id: string]: ThreadInfo,
} = createSelector(
(state: BaseAppState<*>) => state.threadStore.threadInfos,
(state: BaseAppState<>) => state.threadStore.threadInfos,
threadInfoSelector,
(
rawThreadInfos: { +[id: string]: RawThreadInfo },
Expand Down Expand Up @@ -423,8 +421,8 @@ const baseSavedEmojiAvatarSelectorForThread = (
containingThreadID: ?string,
) =>
createSelector(
(state: BaseAppState<*>) => threadInfoSelector(state)[threadID],
(state: BaseAppState<*>) =>
(state: BaseAppState<>) => threadInfoSelector(state)[threadID],
(state: BaseAppState<>) =>
containingThreadID ? threadInfoSelector(state)[containingThreadID] : null,
(threadInfo: ThreadInfo, containingThreadInfo: ?ThreadInfo) => {
return () => {
Expand All @@ -440,7 +438,7 @@ const baseSavedEmojiAvatarSelectorForThread = (
const savedEmojiAvatarSelectorForThread: (
threadID: string,
containingThreadID: ?string,
) => (state: BaseAppState<*>) => () => ClientEmojiAvatar = _memoize(
) => (state: BaseAppState<>) => () => ClientEmojiAvatar = _memoize(
baseSavedEmojiAvatarSelectorForThread,
);

Expand Down
Loading

0 comments on commit c451a81

Please sign in to comment.