From 61a2ed258338cb490f35f8d5db3b8bee8407acf7 Mon Sep 17 00:00:00 2001 From: infinite-persistence Date: Thu, 4 Nov 2021 12:46:01 +0800 Subject: [PATCH] Simplify superchat selectors - memo not required ... since there are no transformations. --- ui/component/livestreamComments/index.js | 8 +++--- ui/redux/selectors/comments.js | 32 +++++++++--------------- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/ui/component/livestreamComments/index.js b/ui/component/livestreamComments/index.js index e7b3d263d..8325d74ef 100644 --- a/ui/component/livestreamComments/index.js +++ b/ui/component/livestreamComments/index.js @@ -5,8 +5,8 @@ import { doCommentList, doSuperChatList } from 'redux/actions/comments'; import { selectTopLevelCommentsForUri, selectIsFetchingComments, - makeSelectSuperChatsForUri, - makeSelectSuperChatTotalAmountForUri, + selectSuperChatsForUri, + selectSuperChatTotalAmountForUri, selectPinnedCommentsForUri, } from 'redux/selectors/comments'; import LivestreamComments from './view'; @@ -18,8 +18,8 @@ const select = (state, props) => ({ comments: selectTopLevelCommentsForUri(state, props.uri, MAX_LIVESTREAM_COMMENTS), pinnedComments: selectPinnedCommentsForUri(state, props.uri), fetchingComments: selectIsFetchingComments(state), - superChats: makeSelectSuperChatsForUri(props.uri)(state), - superChatsTotalAmount: makeSelectSuperChatTotalAmountForUri(props.uri)(state), + superChats: selectSuperChatsForUri(state, props.uri), + superChatsTotalAmount: selectSuperChatTotalAmountForUri(state, props.uri), myChannels: selectMyChannelClaims(state), }); diff --git a/ui/redux/selectors/comments.js b/ui/redux/selectors/comments.js index 5b3b58963..2ae39d16a 100644 --- a/ui/redux/selectors/comments.js +++ b/ui/redux/selectors/comments.js @@ -368,25 +368,17 @@ export const makeSelectUriIsBlockingOrUnBlocking = (uri: string) => return blockingByUri[uri] || unBlockingByUri[uri]; }); -export const makeSelectSuperChatDataForUri = (uri: string) => - createSelector(selectSuperchatsByUri, (byUri) => { - return byUri[uri]; - }); +export const selectSuperChatDataForUri = (state: State, uri: string) => { + const byUri = selectSuperchatsByUri(state); + return byUri[uri]; +}; -export const makeSelectSuperChatsForUri = (uri: string) => - createSelector(makeSelectSuperChatDataForUri(uri), (superChatData) => { - if (!superChatData) { - return undefined; - } +export const selectSuperChatsForUri = (state: State, uri: string) => { + const superChatData = selectSuperChatDataForUri(state, uri); + return superChatData ? superChatData.comments : undefined; +}; - return superChatData.comments; - }); - -export const makeSelectSuperChatTotalAmountForUri = (uri: string) => - createSelector(makeSelectSuperChatDataForUri(uri), (superChatData) => { - if (!superChatData) { - return 0; - } - - return superChatData.totalAmount; - }); +export const selectSuperChatTotalAmountForUri = (state: State, uri: string) => { + const superChatData = selectSuperChatDataForUri(state, uri); + return superChatData ? superChatData.totalAmount : 0; +};