Simplify makeSelectIsUriResolving

- Memo not required. `resolvingUris` is very dynamic and is a short array anyways.
- Changeg from using `indexOf` to `includes`, which is more concise.
This commit is contained in:
infinite-persistence 2021-11-16 12:43:28 +08:00
parent bf324a1b79
commit 201a826381
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0
19 changed files with 47 additions and 49 deletions

View file

@ -1,10 +1,10 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { makeSelectClaimForUri, makeSelectIsUriResolving } from 'redux/selectors/claims'; import { selectClaimForUri, selectIsUriResolving } from 'redux/selectors/claims';
import ChannelMentionSuggestion from './view'; import ChannelMentionSuggestion from './view';
const select = (state, props) => ({ const select = (state, props) => ({
claim: makeSelectClaimForUri(props.uri)(state), claim: selectClaimForUri(state, props.uri),
isResolvingUri: makeSelectIsUriResolving(props.uri)(state), isResolvingUri: selectIsUriResolving(state, props.uri),
}); });
export default connect(select)(ChannelMentionSuggestion); export default connect(select)(ChannelMentionSuggestion);

View file

@ -1,5 +1,5 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { makeSelectIsUriResolving } from 'redux/selectors/claims'; import { selectIsUriResolving } from 'redux/selectors/claims';
import { doResolveUri } from 'redux/actions/claims'; import { doResolveUri } from 'redux/actions/claims';
import { makeSelectWinningUriForQuery } from 'redux/selectors/search'; import { makeSelectWinningUriForQuery } from 'redux/selectors/search';
import ChannelMentionTopSuggestion from './view'; import ChannelMentionTopSuggestion from './view';
@ -8,7 +8,7 @@ const select = (state, props) => {
const uriFromQuery = `lbry://${props.query}`; const uriFromQuery = `lbry://${props.query}`;
return { return {
uriFromQuery, uriFromQuery,
isResolvingUri: makeSelectIsUriResolving(uriFromQuery)(state), isResolvingUri: selectIsUriResolving(state, uriFromQuery),
winningUri: makeSelectWinningUriForQuery(props.query)(state), winningUri: makeSelectWinningUriForQuery(props.query)(state),
}; };
}; };

View file

@ -1,12 +1,12 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { selectThumbnailForUri, selectClaimForUri, makeSelectIsUriResolving } from 'redux/selectors/claims'; import { selectThumbnailForUri, selectClaimForUri, selectIsUriResolving } from 'redux/selectors/claims';
import { doResolveUri } from 'redux/actions/claims'; import { doResolveUri } from 'redux/actions/claims';
import ChannelThumbnail from './view'; import ChannelThumbnail from './view';
const select = (state, props) => ({ const select = (state, props) => ({
thumbnail: selectThumbnailForUri(state, props.uri), thumbnail: selectThumbnailForUri(state, props.uri),
claim: selectClaimForUri(state, props.uri), claim: selectClaimForUri(state, props.uri),
isResolving: makeSelectIsUriResolving(props.uri)(state), isResolving: selectIsUriResolving(state, props.uri),
}); });
export default connect(select, { export default connect(select, {

View file

@ -1,5 +1,5 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { makeSelectClaimForUri, makeSelectIsUriResolving } from 'redux/selectors/claims'; import { makeSelectClaimForUri, selectIsUriResolving } from 'redux/selectors/claims';
import { doResolveUri } from 'redux/actions/claims'; import { doResolveUri } from 'redux/actions/claims';
import { doSetPlayingUri } from 'redux/actions/content'; import { doSetPlayingUri } from 'redux/actions/content';
import { punctuationMarks } from 'util/remark-lbry'; import { punctuationMarks } from 'util/remark-lbry';
@ -25,7 +25,7 @@ const select = (state, props) => {
uri, uri,
claim, claim,
fullUri: props.uri, fullUri: props.uri,
isResolvingUri: makeSelectIsUriResolving(uri)(state), isResolvingUri: selectIsUriResolving(state, uri),
blackListedOutpoints: selectBlackListedOutpoints(state), blackListedOutpoints: selectBlackListedOutpoints(state),
playingUri: selectPlayingUri(state), playingUri: selectPlayingUri(state),
}; };

View file

@ -1,7 +1,7 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { import {
selectClaimForUri, selectClaimForUri,
makeSelectIsUriResolving, selectIsUriResolving,
selectClaimIsMine, selectClaimIsMine,
makeSelectClaimIsPending, makeSelectClaimIsPending,
makeSelectReflectingClaimForUri, makeSelectReflectingClaimForUri,
@ -44,8 +44,8 @@ const select = (state, props) => {
reflectingProgress: props.uri && makeSelectReflectingClaimForUri(props.uri)(state), reflectingProgress: props.uri && makeSelectReflectingClaimForUri(props.uri)(state),
obscureNsfw: selectShowMatureContent(state) === false, obscureNsfw: selectShowMatureContent(state) === false,
claimIsMine: props.uri && selectClaimIsMine(state, claim), claimIsMine: props.uri && selectClaimIsMine(state, claim),
isResolvingUri: props.uri && makeSelectIsUriResolving(props.uri)(state), isResolvingUri: props.uri && selectIsUriResolving(state, props.uri),
isResolvingRepost: props.uri && makeSelectIsUriResolving(props.repostUrl)(state), isResolvingRepost: props.uri && selectIsUriResolving(state, props.repostUrl),
nsfw: claim ? isClaimNsfw(claim) : false, nsfw: claim ? isClaimNsfw(claim) : false,
banState: selectBanStateForUri(state, props.uri), banState: selectBanStateForUri(state, props.uri),
hasVisitedUri: props.uri && makeSelectHasVisitedUri(props.uri)(state), hasVisitedUri: props.uri && makeSelectHasVisitedUri(props.uri)(state),

View file

@ -1,7 +1,7 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { import {
makeSelectClaimForUri, makeSelectClaimForUri,
makeSelectIsUriResolving, selectIsUriResolving,
getThumbnailFromClaim, getThumbnailFromClaim,
selectTitleForUri, selectTitleForUri,
isStreamPlaceholderClaim, isStreamPlaceholderClaim,
@ -26,7 +26,7 @@ const select = (state, props) => {
claim, claim,
mediaDuration, mediaDuration,
date: props.uri && selectDateForUri(state, props.uri), date: props.uri && selectDateForUri(state, props.uri),
isResolvingUri: props.uri && makeSelectIsUriResolving(props.uri)(state), isResolvingUri: props.uri && selectIsUriResolving(state, props.uri),
thumbnail: getThumbnailFromClaim(claim), thumbnail: getThumbnailFromClaim(claim),
title: props.uri && selectTitleForUri(state, props.uri), title: props.uri && selectTitleForUri(state, props.uri),
banState: selectBanStateForUri(state, props.uri), banState: selectBanStateForUri(state, props.uri),

View file

@ -1,5 +1,5 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { makeSelectIsUriResolving, selectClaimIdForUri, makeSelectClaimForClaimId } from 'redux/selectors/claims'; import { selectIsUriResolving, selectClaimIdForUri, makeSelectClaimForClaimId } from 'redux/selectors/claims';
import { import {
makeSelectUrlsForCollectionId, makeSelectUrlsForCollectionId,
makeSelectNameForCollectionId, makeSelectNameForCollectionId,
@ -22,7 +22,7 @@ const select = (state, props) => {
collectionItemUrls: makeSelectUrlsForCollectionId(collectionId)(state), // ForId || ForUri collectionItemUrls: makeSelectUrlsForCollectionId(collectionId)(state), // ForId || ForUri
pendingCollection: makeSelectPendingCollectionForId(collectionId)(state), pendingCollection: makeSelectPendingCollectionForId(collectionId)(state),
claim, claim,
isResolvingUri: collectionUri && makeSelectIsUriResolving(collectionUri)(state), isResolvingUri: collectionUri && selectIsUriResolving(state, collectionUri),
}; };
}; };

View file

@ -1,6 +1,6 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { import {
makeSelectIsUriResolving, selectIsUriResolving,
getThumbnailFromClaim, getThumbnailFromClaim,
selectTitleForUri, selectTitleForUri,
makeSelectChannelForClaimUri, makeSelectChannelForClaimUri,
@ -39,7 +39,7 @@ const select = (state, props) => {
claim, claim,
isResolvingCollectionClaims: makeSelectIsResolvingCollectionForId(collectionId)(state), isResolvingCollectionClaims: makeSelectIsResolvingCollectionForId(collectionId)(state),
channelClaim: collectionUri && makeSelectChannelForClaimUri(collectionUri)(state), channelClaim: collectionUri && makeSelectChannelForClaimUri(collectionUri)(state),
isResolvingUri: collectionUri && makeSelectIsUriResolving(collectionUri)(state), isResolvingUri: collectionUri && selectIsUriResolving(state, collectionUri),
thumbnail: getThumbnailFromClaim(claim), thumbnail: getThumbnailFromClaim(claim),
title: collectionUri && selectTitleForUri(state, collectionUri), title: collectionUri && selectTitleForUri(state, collectionUri),
blackListedOutpoints: selectBlackListedOutpoints(state), blackListedOutpoints: selectBlackListedOutpoints(state),

View file

@ -4,7 +4,7 @@ import {
selectTitleForUri, selectTitleForUri,
getThumbnailFromClaim, getThumbnailFromClaim,
selectClaimForUri, selectClaimForUri,
makeSelectIsUriResolving, selectIsUriResolving,
makeSelectMetadataItemForUri, makeSelectMetadataItemForUri,
} from 'redux/selectors/claims'; } from 'redux/selectors/claims';
import { doResolveUri } from 'redux/actions/claims'; import { doResolveUri } from 'redux/actions/claims';
@ -21,7 +21,7 @@ const select = (state, props) => {
thumbnail: getThumbnailFromClaim(claim), thumbnail: getThumbnailFromClaim(claim),
description: makeSelectMetadataItemForUri(props.uri, 'description')(state), description: makeSelectMetadataItemForUri(props.uri, 'description')(state),
channelIsMine: selectClaimIsMine(state, claim), channelIsMine: selectClaimIsMine(state, claim),
isResolvingUri: makeSelectIsUriResolving(props.uri)(state), isResolvingUri: selectIsUriResolving(state, props.uri),
blackListedOutpoints: selectBlackListedOutpoints(state), blackListedOutpoints: selectBlackListedOutpoints(state),
}; };
}; };

View file

@ -7,7 +7,7 @@ import {
selectRepostLoading, selectRepostLoading,
selectMyClaimsWithoutChannels, selectMyClaimsWithoutChannels,
makeSelectEffectiveAmountForUri, makeSelectEffectiveAmountForUri,
makeSelectIsUriResolving, selectIsUriResolving,
selectFetchingMyChannels, selectFetchingMyChannels,
} from 'redux/selectors/claims'; } from 'redux/selectors/claims';
@ -34,8 +34,8 @@ const select = (state, props) => ({
error: selectRepostError(state), error: selectRepostError(state),
reposting: selectRepostLoading(state), reposting: selectRepostLoading(state),
myClaims: selectMyClaimsWithoutChannels(state), myClaims: selectMyClaimsWithoutChannels(state),
isResolvingPassedRepost: props.name && makeSelectIsUriResolving(`lbry://${props.name}`)(state), isResolvingPassedRepost: props.name && selectIsUriResolving(state, `lbry://${props.name}`),
isResolvingEnteredRepost: props.repostUri && makeSelectIsUriResolving(`lbry://${props.repostUri}`)(state), isResolvingEnteredRepost: props.repostUri && selectIsUriResolving(state, `lbry://${props.repostUri}`),
activeChannelClaim: selectActiveChannelClaim(state), activeChannelClaim: selectActiveChannelClaim(state),
fetchingMyChannels: selectFetchingMyChannels(state), fetchingMyChannels: selectFetchingMyChannels(state),
incognito: selectIncognito(state), incognito: selectIncognito(state),

View file

@ -2,7 +2,7 @@ import { connect } from 'react-redux';
import { doClearPublish, doPrepareEdit } from 'redux/actions/publish'; import { doClearPublish, doPrepareEdit } from 'redux/actions/publish';
import { doResolveUris } from 'redux/actions/claims'; import { doResolveUris } from 'redux/actions/claims';
import { selectPendingIds, makeSelectClaimForUri } from 'redux/selectors/claims'; import { selectPendingIds, makeSelectClaimForUri } from 'redux/selectors/claims';
import { makeSelectWinningUriForQuery, makeSelectIsResolvingWinningUri } from 'redux/selectors/search'; import { makeSelectWinningUriForQuery, selectIsResolvingWinningUri } from 'redux/selectors/search';
import SearchTopClaim from './view'; import SearchTopClaim from './view';
import { push } from 'connected-react-router'; import { push } from 'connected-react-router';
import * as PAGES from 'constants/pages'; import * as PAGES from 'constants/pages';
@ -13,7 +13,7 @@ const select = (state, props) => {
return { return {
winningUri, winningUri,
winningClaim: winningUri ? makeSelectClaimForUri(winningUri)(state) : undefined, winningClaim: winningUri ? makeSelectClaimForUri(winningUri)(state) : undefined,
isResolvingWinningUri: props.query ? makeSelectIsResolvingWinningUri(props.query)(state) : false, isResolvingWinningUri: props.query ? selectIsResolvingWinningUri(state, props.query) : false,
pendingIds: selectPendingIds(state), pendingIds: selectPendingIds(state),
}; };
}; };

View file

@ -1,12 +1,12 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { normalizeURI } from 'util/lbryURI'; import { normalizeURI } from 'util/lbryURI';
import { doResolveUri } from 'redux/actions/claims'; import { doResolveUri } from 'redux/actions/claims';
import { makeSelectIsUriResolving, makeSelectClaimForUri } from 'redux/selectors/claims'; import { selectIsUriResolving, makeSelectClaimForUri } from 'redux/selectors/claims';
import UriIndicator from './view'; import UriIndicator from './view';
const select = (state, props) => ({ const select = (state, props) => ({
claim: makeSelectClaimForUri(props.uri)(state), claim: makeSelectClaimForUri(props.uri)(state),
isResolvingUri: makeSelectIsUriResolving(props.uri)(state), isResolvingUri: selectIsUriResolving(state, props.uri),
uri: normalizeURI(props.uri), uri: normalizeURI(props.uri),
}); });

View file

@ -1,10 +1,10 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { makeSelectClaimForUri, makeSelectIsUriResolving } from 'redux/selectors/claims'; import { selectClaimForUri, selectIsUriResolving } from 'redux/selectors/claims';
import WunderbarSuggestion from './view'; import WunderbarSuggestion from './view';
const select = (state, props) => ({ const select = (state, props) => ({
claim: makeSelectClaimForUri(props.uri)(state), claim: selectClaimForUri(state, props.uri),
isResolvingUri: makeSelectIsUriResolving(props.uri)(state), isResolvingUri: selectIsUriResolving(state, props.uri),
}); });
export default connect(select)(WunderbarSuggestion); export default connect(select)(WunderbarSuggestion);

View file

@ -1,7 +1,7 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { import {
makeSelectClaimForUri, makeSelectClaimForUri,
makeSelectIsUriResolving, selectIsUriResolving,
makeSelectTagInClaimOrChannelForUri, makeSelectTagInClaimOrChannelForUri,
} from 'redux/selectors/claims'; } from 'redux/selectors/claims';
import { doResolveUris } from 'redux/actions/claims'; import { doResolveUris } from 'redux/actions/claims';
@ -23,7 +23,7 @@ const select = (state, props) => {
} }
} catch (e) {} } catch (e) {}
const resolvingUris = uris.some((uri) => makeSelectIsUriResolving(uri)(state)); const resolvingUris = uris.some((uri) => selectIsUriResolving(state, uri));
const winningUri = makeSelectWinningUriForQuery(props.query)(state); const winningUri = makeSelectWinningUriForQuery(props.query)(state);
const winningClaim = winningUri ? makeSelectClaimForUri(winningUri)(state) : undefined; const winningClaim = winningUri ? makeSelectClaimForUri(winningUri)(state) : undefined;
const preferEmbed = makeSelectTagInClaimOrChannelForUri(winningUri, PREFERENCE_EMBED)(state); const preferEmbed = makeSelectTagInClaimOrChannelForUri(winningUri, PREFERENCE_EMBED)(state);

View file

@ -1,6 +1,6 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import EmbedWrapperPage from './view'; import EmbedWrapperPage from './view';
import { makeSelectClaimForUri, makeSelectIsUriResolving } from 'redux/selectors/claims'; import { makeSelectClaimForUri, selectIsUriResolving } from 'redux/selectors/claims';
import { makeSelectStreamingUrlForUri } from 'redux/selectors/file_info'; import { makeSelectStreamingUrlForUri } from 'redux/selectors/file_info';
import { doResolveUri } from 'redux/actions/claims'; import { doResolveUri } from 'redux/actions/claims';
import { buildURI } from 'util/lbryURI'; import { buildURI } from 'util/lbryURI';
@ -17,7 +17,7 @@ const select = (state, props) => {
claim: makeSelectClaimForUri(uri)(state), claim: makeSelectClaimForUri(uri)(state),
costInfo: makeSelectCostInfoForUri(uri)(state), costInfo: makeSelectCostInfoForUri(uri)(state),
streamingUrl: makeSelectStreamingUrlForUri(uri)(state), streamingUrl: makeSelectStreamingUrlForUri(uri)(state),
isResolvingUri: makeSelectIsUriResolving(uri)(state), isResolvingUri: selectIsUriResolving(state, uri),
blackListedOutpoints: selectBlackListedOutpoints(state), blackListedOutpoints: selectBlackListedOutpoints(state),
}; };
}; };

View file

@ -5,7 +5,7 @@ import { withRouter } from 'react-router';
import { PAGE_SIZE } from 'constants/claim'; import { PAGE_SIZE } from 'constants/claim';
import { import {
makeSelectClaimForUri, makeSelectClaimForUri,
makeSelectIsUriResolving, selectIsUriResolving,
makeSelectTotalPagesForChannel, makeSelectTotalPagesForChannel,
selectTitleForUri, selectTitleForUri,
selectClaimIsMine, selectClaimIsMine,
@ -72,7 +72,7 @@ const select = (state, props) => {
return { return {
uri, uri,
claim, claim,
isResolvingUri: makeSelectIsUriResolving(uri)(state), isResolvingUri: selectIsUriResolving(state, uri),
blackListedOutpoints: selectBlackListedOutpoints(state), blackListedOutpoints: selectBlackListedOutpoints(state),
totalPages: makeSelectTotalPagesForChannel(uri, PAGE_SIZE)(state), totalPages: makeSelectTotalPagesForChannel(uri, PAGE_SIZE)(state),
isSubscribed: makeSelectChannelInSubscriptions(uri)(state), isSubscribed: makeSelectChannelInSubscriptions(uri)(state),

View file

@ -12,7 +12,7 @@ import { getRecommendationSearchOptions } from 'util/search';
import { SEARCH_SERVER_API } from 'config'; import { SEARCH_SERVER_API } from 'config';
type Dispatch = (action: any) => any; type Dispatch = (action: any) => any;
type GetState = () => { search: SearchState }; type GetState = () => { claims: any, search: SearchState };
type SearchOptions = { type SearchOptions = {
size?: number, size?: number,

View file

@ -519,8 +519,10 @@ export const selectResolvingUris = createSelector(selectState, (state) => state.
export const selectChannelImportPending = (state: State) => selectState(state).pendingChannelImport; export const selectChannelImportPending = (state: State) => selectState(state).pendingChannelImport;
export const makeSelectIsUriResolving = (uri: string) => export const selectIsUriResolving = (state: State, uri: string) => {
createSelector(selectResolvingUris, (resolvingUris) => resolvingUris && resolvingUris.indexOf(uri) !== -1); const resolvingUris = selectResolvingUris(state);
return resolvingUris && resolvingUris.includes(uri);
};
export const selectPlayingUri = (state: State) => selectState(state).playingUri; export const selectPlayingUri = (state: State) => selectState(state).playingUri;

View file

@ -8,7 +8,7 @@ import {
makeSelectClaimForClaimId, makeSelectClaimForClaimId,
selectClaimIsNsfwForUri, selectClaimIsNsfwForUri,
makeSelectPendingClaimForUri, makeSelectPendingClaimForUri,
makeSelectIsUriResolving, selectIsUriResolving,
} from 'redux/selectors/claims'; } from 'redux/selectors/claims';
import { parseURI } from 'util/lbryURI'; import { parseURI } from 'util/lbryURI';
import { isClaimNsfw } from 'util/claim'; import { isClaimNsfw } from 'util/claim';
@ -20,7 +20,7 @@ import { selectHistory } from 'redux/selectors/content';
import { selectAllCostInfoByUri } from 'lbryinc'; import { selectAllCostInfoByUri } from 'lbryinc';
import { SIMPLE_SITE } from 'config'; import { SIMPLE_SITE } from 'config';
type State = { search: SearchState }; type State = { claims: any, search: SearchState };
export const selectState = (state: State): SearchState => state.search; export const selectState = (state: State): SearchState => state.search;
@ -235,7 +235,7 @@ export const makeSelectWinningUriForQuery = (query: string) => {
); );
}; };
export const makeSelectIsResolvingWinningUri = (query: string = '') => { export const selectIsResolvingWinningUri = (state: State, query: string = '') => {
const uriFromQuery = `lbry://${query}`; const uriFromQuery = `lbry://${query}`;
let channelUriFromQuery; let channelUriFromQuery;
try { try {
@ -245,13 +245,9 @@ export const makeSelectIsResolvingWinningUri = (query: string = '') => {
} }
} catch (e) {} } catch (e) {}
return createSelector( const claim1IsResolving = selectIsUriResolving(state, uriFromQuery);
makeSelectIsUriResolving(uriFromQuery), const claim2IsResolving = channelUriFromQuery ? selectIsUriResolving(state, channelUriFromQuery) : false;
channelUriFromQuery ? makeSelectIsUriResolving(channelUriFromQuery) : () => {}, return claim1IsResolving || claim2IsResolving;
(claim1IsResolving, claim2IsResolving) => {
return claim1IsResolving || claim2IsResolving;
}
);
}; };
export const makeSelectUrlForClaimId = (claimId: string) => export const makeSelectUrlForClaimId = (claimId: string) =>