Comment-store: Don't memoize selectors without transformation

This commit is contained in:
infinite-persistence 2021-10-11 11:22:05 +08:00
parent 5d8fc40051
commit b6ad4ae974
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0
2 changed files with 26 additions and 44 deletions

View file

@ -45,6 +45,7 @@ declare type CommentsState = {
isLoading: boolean, isLoading: boolean,
isLoadingById: boolean, isLoadingById: boolean,
isLoadingByParentId: { [string]: boolean }, isLoadingByParentId: { [string]: boolean },
isCommenting: boolean,
myComments: ?Set<string>, myComments: ?Set<string>,
isFetchingReacts: boolean, isFetchingReacts: boolean,
myReactsByCommentId: ?{ [string]: Array<string> }, // {"CommentId:MyChannelId": ["like", "dislike", ...]} myReactsByCommentId: ?{ [string]: Array<string> }, // {"CommentId:MyChannelId": ["like", "dislike", ...]}

View file

@ -10,11 +10,11 @@ type State = { comments: CommentsState };
const selectState = (state) => state.comments || {}; const selectState = (state) => state.comments || {};
export const selectCommentsById = createSelector(selectState, (state) => state.commentById || {}); export const selectCommentsById = (state: State) => selectState(state).commentById || {};
export const selectIsFetchingComments = createSelector(selectState, (state) => state.isLoading); export const selectIsFetchingComments = (state: State) => selectState(state).isLoading;
export const selectIsFetchingCommentsById = createSelector(selectState, (state) => state.isLoadingById); export const selectIsFetchingCommentsById = (state: State) => selectState(state).isLoadingById;
export const selectIsFetchingCommentsByParentId = createSelector(selectState, (state) => state.isLoadingByParentId); export const selectIsFetchingCommentsByParentId = (state: State) => selectState(state).isLoadingByParentId;
export const selectIsFetchingReacts = createSelector(selectState, (state) => state.isFetchingReacts); export const selectIsFetchingReacts = (state: State) => selectState(state).isFetchingReacts;
export const selectMyReacts = (state: State) => state.comments.myReactsByCommentId; export const selectMyReacts = (state: State) => state.comments.myReactsByCommentId;
export const selectMyReactsForComment = (state: State, commentIdChannelId: string) => { export const selectMyReactsForComment = (state: State, commentIdChannelId: string) => {
@ -27,7 +27,7 @@ export const selectOthersReactsForComment = (state: State, id: string) => {
return state.comments.othersReactsByCommentId && state.comments.othersReactsByCommentId[id]; return state.comments.othersReactsByCommentId && state.comments.othersReactsByCommentId[id];
}; };
export const selectPinnedCommentsById = createSelector(selectState, (state) => state.pinnedCommentsById); export const selectPinnedCommentsById = (state: State) => selectState(state).pinnedCommentsById;
export const makeSelectPinnedCommentsForUri = (uri: string) => export const makeSelectPinnedCommentsForUri = (uri: string) =>
createSelector( createSelector(
selectCommentsByUri, selectCommentsByUri,
@ -61,35 +61,19 @@ export const selectModeratorBlockList = createSelector(selectState, (state) =>
state.moderatorBlockList ? state.moderatorBlockList.reverse() : [] state.moderatorBlockList ? state.moderatorBlockList.reverse() : []
); );
export const selectPersonalTimeoutMap = createSelector(selectState, (state) => state.personalTimeoutMap); export const selectPersonalTimeoutMap = (state: State) => selectState(state).personalTimeoutMap;
export const selectAdminTimeoutMap = createSelector(selectState, (state) => state.adminTimeoutMap); export const selectAdminTimeoutMap = (state: State) => selectState(state).adminTimeoutMap;
export const selectModeratorTimeoutMap = createSelector(selectState, (state) => state.moderatorTimeoutMap); export const selectModeratorTimeoutMap = (state: State) => selectState(state).moderatorTimeoutMap;
export const selectModeratorBlockListDelegatorsMap = (state: State) =>
export const selectModeratorBlockListDelegatorsMap = createSelector( selectState(state).moderatorBlockListDelegatorsMap;
selectState, export const selectTogglingForDelegatorMap = (state: State) => selectState(state).togglingForDelegatorMap;
(state) => state.moderatorBlockListDelegatorsMap export const selectBlockingByUri = (state: State) => selectState(state).blockingByUri;
); export const selectUnBlockingByUri = (state: State) => selectState(state).unBlockingByUri;
export const selectFetchingModerationBlockList = (state: State) => selectState(state).fetchingModerationBlockList;
export const selectTogglingForDelegatorMap = createSelector(selectState, (state) => state.togglingForDelegatorMap); export const selectModerationDelegatesById = (state: State) => selectState(state).moderationDelegatesById;
export const selectIsFetchingModerationDelegates = (state: State) => selectState(state).fetchingModerationDelegates;
export const selectBlockingByUri = createSelector(selectState, (state) => state.blockingByUri); export const selectModerationDelegatorsById = (state: State) => selectState(state).moderationDelegatorsById;
export const selectUnBlockingByUri = createSelector(selectState, (state) => state.unBlockingByUri); export const selectIsFetchingModerationDelegators = (state: State) => selectState(state).fetchingModerationDelegators;
export const selectFetchingModerationBlockList = createSelector(
selectState,
(state) => state.fetchingModerationBlockList
);
export const selectModerationDelegatesById = createSelector(selectState, (state) => state.moderationDelegatesById);
export const selectIsFetchingModerationDelegates = createSelector(
selectState,
(state) => state.fetchingModerationDelegates
);
export const selectModerationDelegatorsById = createSelector(selectState, (state) => state.moderationDelegatorsById);
export const selectIsFetchingModerationDelegators = createSelector(
selectState,
(state) => state.fetchingModerationDelegators
);
export const selectHasAdminChannel = createSelector(selectState, (state) => { export const selectHasAdminChannel = createSelector(selectState, (state) => {
const myChannelIds = Object.keys(state.moderationDelegatorsById); const myChannelIds = Object.keys(state.moderationDelegatorsById);
@ -122,7 +106,7 @@ export const selectCommentsByClaimId = createSelector(selectState, selectComment
return comments; return comments;
}); });
export const selectSuperchatsByUri = createSelector(selectState, (state) => state.superChatsByUri); export const selectSuperchatsByUri = (state: State) => selectState(state).superChatsByUri;
export const selectTopLevelCommentsByClaimId = createSelector(selectState, selectCommentsById, (state, byId) => { export const selectTopLevelCommentsByClaimId = createSelector(selectState, selectCommentsById, (state, byId) => {
const byClaimId = state.topLevelCommentsById || {}; const byClaimId = state.topLevelCommentsById || {};
@ -181,7 +165,7 @@ export const selectCommentsByUri = createSelector(selectState, (state) => {
return comments; return comments;
}); });
export const selectLinkedCommentAncestors = createSelector(selectState, (state) => state.linkedCommentAncestors); export const selectLinkedCommentAncestors = (state: State) => selectState(state).linkedCommentAncestors;
export const makeSelectCommentIdsForUri = (uri: string) => export const makeSelectCommentIdsForUri = (uri: string) =>
createSelector(selectState, selectCommentsByUri, selectClaimsById, (state, byUri) => { createSelector(selectState, selectCommentsByUri, selectClaimsById, (state, byUri) => {
@ -189,13 +173,10 @@ export const makeSelectCommentIdsForUri = (uri: string) =>
return state.byId[claimId]; return state.byId[claimId];
}); });
export const selectPendingCommentReacts = createSelector(selectState, (state) => state.pendingCommentReactions); export const selectPendingCommentReacts = (state: State) => selectState(state).pendingCommentReactions;
export const selectSettingsByChannelId = (state: State) => selectState(state).settingsByChannelId;
export const selectSettingsByChannelId = createSelector(selectState, (state) => state.settingsByChannelId); export const selectFetchingCreatorSettings = (state: State) => selectState(state).fetchingSettings;
export const selectFetchingBlockedWords = (state: State) => selectState(state).fetchingBlockedWords;
export const selectFetchingCreatorSettings = createSelector(selectState, (state) => state.fetchingSettings);
export const selectFetchingBlockedWords = createSelector(selectState, (state) => state.fetchingBlockedWords);
export const makeSelectCommentsForUri = (uri: string) => export const makeSelectCommentsForUri = (uri: string) =>
createSelector( createSelector(