Simplify 'selectClaimIdForUri'

Memoization is not needed. But note that it is now a 2 parameter selector.
This commit is contained in:
infinite-persistence 2021-11-09 20:23:09 +08:00
parent ece2312ec5
commit 7cefb0fadc
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0
4 changed files with 7 additions and 8 deletions

View file

@ -1,5 +1,5 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { makeSelectClaimIdForUri } from 'redux/selectors/claims'; import { selectClaimIdForUri } from 'redux/selectors/claims';
import { import {
doCommentModUnBlock, doCommentModUnBlock,
doCommentModBlock, doCommentModBlock,
@ -43,7 +43,7 @@ const select = (state, props) => {
isBlocked, isBlocked,
isToggling, isToggling,
isBlockingOrUnBlocking: makeSelectUriIsBlockingOrUnBlocking(props.uri)(state), isBlockingOrUnBlocking: makeSelectUriIsBlockingOrUnBlocking(props.uri)(state),
creatorId: makeSelectClaimIdForUri(props.creatorUri)(state), creatorId: selectClaimIdForUri(state, props.creatorUri),
}; };
}; };

View file

@ -1,5 +1,5 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { makeSelectIsUriResolving, makeSelectClaimIdForUri, makeSelectClaimForClaimId } from 'redux/selectors/claims'; import { makeSelectIsUriResolving, selectClaimIdForUri, makeSelectClaimForClaimId } from 'redux/selectors/claims';
import { import {
makeSelectUrlsForCollectionId, makeSelectUrlsForCollectionId,
makeSelectNameForCollectionId, makeSelectNameForCollectionId,
@ -10,7 +10,7 @@ import { doFetchItemsInCollection } from 'redux/actions/collections';
import CollectionPreviewOverlay from './view'; import CollectionPreviewOverlay from './view';
const select = (state, props) => { const select = (state, props) => {
const collectionId = props.collectionId || (props.uri && makeSelectClaimIdForUri(props.uri)); const collectionId = props.collectionId || (props.uri && selectClaimIdForUri(state, props.uri));
const claim = props.collectionId && makeSelectClaimForClaimId(props.collectionId)(state); const claim = props.collectionId && makeSelectClaimForClaimId(props.collectionId)(state);
const collectionUri = props.uri || (claim && (claim.canonical_url || claim.permanent_url)) || null; const collectionUri = props.uri || (claim && (claim.canonical_url || claim.permanent_url)) || null;

View file

@ -5,7 +5,7 @@ import {
makeSelectTitleForUri, makeSelectTitleForUri,
makeSelectChannelForClaimUri, makeSelectChannelForClaimUri,
makeSelectClaimIsNsfw, makeSelectClaimIsNsfw,
makeSelectClaimIdForUri, selectClaimIdForUri,
makeSelectClaimForClaimId, makeSelectClaimForClaimId,
} from 'redux/selectors/claims'; } from 'redux/selectors/claims';
import { import {
@ -24,7 +24,7 @@ import { selectShowMatureContent } from 'redux/selectors/settings';
import CollectionPreviewTile from './view'; import CollectionPreviewTile from './view';
const select = (state, props) => { const select = (state, props) => {
const collectionId = props.collectionId || (props.uri && makeSelectClaimIdForUri(props.uri)); const collectionId = props.collectionId || (props.uri && selectClaimIdForUri(state, props.uri));
const claim = props.collectionId && makeSelectClaimForClaimId(props.collectionId)(state); const claim = props.collectionId && makeSelectClaimForClaimId(props.collectionId)(state);
const collectionUri = props.uri || (claim && (claim.canonical_url || claim.permanent_url)) || null; const collectionUri = props.uri || (claim && (claim.canonical_url || claim.permanent_url)) || null;

View file

@ -79,8 +79,7 @@ export const makeSelectClaimIdIsPending = (claimId: string) =>
return Boolean(pendingById[claimId]); return Boolean(pendingById[claimId]);
}); });
export const makeSelectClaimIdForUri = (uri: string) => export const selectClaimIdForUri = (state: State, uri: string) => selectClaimIdsByUri(state)[uri];
createSelector(selectClaimIdsByUri, (claimIds) => claimIds[uri]);
export const selectReflectingById = (state: State) => selectState(state).reflectingById; export const selectReflectingById = (state: State) => selectState(state).reflectingById;