a3398843c2
Frequently used; top in perf profile Most of the time, you already have the claim object in the current context. `selectClaimIsMineForUri` will retrieve the claim again, which is wasteful, even if it is memoized (looking up the cache still takes time). Break apart the logic and added the alternative `selectClaimIsMine` for faster lookup. Co-authored-by: infinite-persistence <inf.persistence@gmail.com>
33 lines
1.5 KiB
JavaScript
33 lines
1.5 KiB
JavaScript
import { connect } from 'react-redux';
|
|
import { makeSelectIsUriResolving, selectClaimIdForUri, makeSelectClaimForClaimId } from 'redux/selectors/claims';
|
|
import {
|
|
makeSelectUrlsForCollectionId,
|
|
makeSelectNameForCollectionId,
|
|
makeSelectPendingCollectionForId,
|
|
makeSelectCountForCollectionId,
|
|
} from 'redux/selectors/collections';
|
|
import { doFetchItemsInCollection } from 'redux/actions/collections';
|
|
import CollectionPreviewOverlay from './view';
|
|
|
|
const select = (state, props) => {
|
|
const collectionId = props.collectionId || (props.uri && selectClaimIdForUri(state, props.uri));
|
|
const claim = props.collectionId && makeSelectClaimForClaimId(props.collectionId)(state);
|
|
const collectionUri = props.uri || (claim && (claim.canonical_url || claim.permanent_url)) || null;
|
|
|
|
return {
|
|
collectionId,
|
|
uri: collectionUri,
|
|
collectionCount: makeSelectCountForCollectionId(collectionId)(state),
|
|
collectionName: makeSelectNameForCollectionId(collectionId)(state),
|
|
collectionItemUrls: makeSelectUrlsForCollectionId(collectionId)(state), // ForId || ForUri
|
|
pendingCollection: makeSelectPendingCollectionForId(collectionId)(state),
|
|
claim,
|
|
isResolvingUri: collectionUri && makeSelectIsUriResolving(collectionUri)(state),
|
|
};
|
|
};
|
|
|
|
const perform = (dispatch) => ({
|
|
fetchCollectionItems: (claimId) => dispatch(doFetchItemsInCollection({ collectionId: claimId })), // if collection not resolved, resolve it
|
|
});
|
|
|
|
export default connect(select, perform)(CollectionPreviewOverlay);
|