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 { makeSelectClaimForUri, makeSelectIsUriResolving } from 'redux/selectors/claims';
import { selectClaimForUri, selectIsUriResolving } from 'redux/selectors/claims';
import ChannelMentionSuggestion from './view';
const select = (state, props) => ({
claim: makeSelectClaimForUri(props.uri)(state),
isResolvingUri: makeSelectIsUriResolving(props.uri)(state),
claim: selectClaimForUri(state, props.uri),
isResolvingUri: selectIsUriResolving(state, props.uri),
});
export default connect(select)(ChannelMentionSuggestion);

View file

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

View file

@ -1,12 +1,12 @@
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 ChannelThumbnail from './view';
const select = (state, props) => ({
thumbnail: selectThumbnailForUri(state, props.uri),
claim: selectClaimForUri(state, props.uri),
isResolving: makeSelectIsUriResolving(props.uri)(state),
isResolving: selectIsUriResolving(state, props.uri),
});
export default connect(select, {

View file

@ -1,5 +1,5 @@
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 { doSetPlayingUri } from 'redux/actions/content';
import { punctuationMarks } from 'util/remark-lbry';
@ -25,7 +25,7 @@ const select = (state, props) => {
uri,
claim,
fullUri: props.uri,
isResolvingUri: makeSelectIsUriResolving(uri)(state),
isResolvingUri: selectIsUriResolving(state, uri),
blackListedOutpoints: selectBlackListedOutpoints(state),
playingUri: selectPlayingUri(state),
};

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -2,7 +2,7 @@ import { connect } from 'react-redux';
import { doClearPublish, doPrepareEdit } from 'redux/actions/publish';
import { doResolveUris } from 'redux/actions/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 { push } from 'connected-react-router';
import * as PAGES from 'constants/pages';
@ -13,7 +13,7 @@ const select = (state, props) => {
return {
winningUri,
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),
};
};

View file

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

View file

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

View file

@ -1,7 +1,7 @@
import { connect } from 'react-redux';
import {
makeSelectClaimForUri,
makeSelectIsUriResolving,
selectIsUriResolving,
makeSelectTagInClaimOrChannelForUri,
} from 'redux/selectors/claims';
import { doResolveUris } from 'redux/actions/claims';
@ -23,7 +23,7 @@ const select = (state, props) => {
}
} 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 winningClaim = winningUri ? makeSelectClaimForUri(winningUri)(state) : undefined;
const preferEmbed = makeSelectTagInClaimOrChannelForUri(winningUri, PREFERENCE_EMBED)(state);

View file

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

View file

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

View file

@ -12,7 +12,7 @@ import { getRecommendationSearchOptions } from 'util/search';
import { SEARCH_SERVER_API } from 'config';
type Dispatch = (action: any) => any;
type GetState = () => { search: SearchState };
type GetState = () => { claims: any, search: SearchState };
type SearchOptions = {
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 makeSelectIsUriResolving = (uri: string) =>
createSelector(selectResolvingUris, (resolvingUris) => resolvingUris && resolvingUris.indexOf(uri) !== -1);
export const selectIsUriResolving = (state: State, uri: string) => {
const resolvingUris = selectResolvingUris(state);
return resolvingUris && resolvingUris.includes(uri);
};
export const selectPlayingUri = (state: State) => selectState(state).playingUri;

View file

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