lbry-desktop/ui/redux/selectors/blocked.js
infinite-persistence a8149fe9bb
Memoize 'mutedAndBlockedChannelIds'
It was being recalculated repeatedly.

This memoizes it, although it still re-calculates occasionally despite none of the source arrays changed. I think it is due to the state change in the Preference Sync.

Note: input selectors to `createSelector` needs to be extractions-only (i.e. must not have transformations). I think most of our `makeSelect*` selectors violate this and broke memoization.
2021-09-29 21:55:01 +08:00

26 lines
893 B
JavaScript

// @flow
import { createSelector } from 'reselect';
import { splitBySeparator } from 'lbry-redux';
const selectState = (state: { blocked: BlocklistState }) => state.blocked || {};
export const selectMutedChannels = createSelector(selectState, (state: BlocklistState) => {
return state.blockedChannels.filter((e) => typeof e === 'string');
});
export const makeSelectChannelIsMuted = (uri: string) =>
createSelector(selectMutedChannels, (state: Array<string>) => {
return state.includes(uri);
});
export const selectMutedAndBlockedChannelIds = createSelector(
selectState,
(state) => state.comments,
(state, commentsState) => {
const mutedUris = state.blockedChannels;
const blockedUris = commentsState.moderationBlockList;
return Array.from(
new Set((mutedUris || []).concat(blockedUris || []).map((uri) => splitBySeparator(uri)[1]))
).sort();
}
);