Fix makeSelectContentPositionForUri memo

- Move away from the leaky makeSelect* pattern.
- No memoization since it's pretty light.
This commit is contained in:
infinite-persistence 2022-04-01 16:18:51 +08:00 committed by Thomas Zarebczan
parent fb998208e2
commit 491c934119
4 changed files with 15 additions and 14 deletions

View file

@ -3,7 +3,7 @@ import { doFetchInviteStatus } from 'redux/actions/user';
import { makeSelectClaimForUri, selectTitleForUri } from 'redux/selectors/claims'; import { makeSelectClaimForUri, selectTitleForUri } from 'redux/selectors/claims';
import SocialShare from './view'; import SocialShare from './view';
import { selectUserInviteReferralCode, selectUser, selectUserInviteStatusFetched } from 'redux/selectors/user'; import { selectUserInviteReferralCode, selectUser, selectUserInviteStatusFetched } from 'redux/selectors/user';
import { makeSelectContentPositionForUri } from 'redux/selectors/content'; import { selectContentPositionForUri } from 'redux/selectors/content';
const select = (state, props) => ({ const select = (state, props) => ({
claim: makeSelectClaimForUri(props.uri)(state), claim: makeSelectClaimForUri(props.uri)(state),
@ -11,7 +11,7 @@ const select = (state, props) => ({
referralCode: selectUserInviteReferralCode(state), referralCode: selectUserInviteReferralCode(state),
user: selectUser(state), user: selectUser(state),
title: selectTitleForUri(state, props.uri), title: selectTitleForUri(state, props.uri),
position: makeSelectContentPositionForUri(props.uri)(state), position: selectContentPositionForUri(state, props.uri),
}); });
const perform = { const perform = {

View file

@ -17,7 +17,7 @@ import {
} from 'redux/actions/app'; } from 'redux/actions/app';
import { selectVolume, selectMute } from 'redux/selectors/app'; import { selectVolume, selectMute } from 'redux/selectors/app';
import { savePosition, clearPosition, doPlayUri, doSetPlayingUri } from 'redux/actions/content'; import { savePosition, clearPosition, doPlayUri, doSetPlayingUri } from 'redux/actions/content';
import { makeSelectContentPositionForUri, makeSelectIsPlayerFloating, selectPlayingUri } from 'redux/selectors/content'; import { makeSelectIsPlayerFloating, selectContentPositionForUri, selectPlayingUri } from 'redux/selectors/content';
import { selectRecommendedContentForUri } from 'redux/selectors/search'; import { selectRecommendedContentForUri } from 'redux/selectors/search';
import VideoViewer from './view'; import VideoViewer from './view';
import { withRouter } from 'react-router'; import { withRouter } from 'react-router';
@ -35,7 +35,7 @@ const select = (state, props) => {
const claim = selectClaimForUri(state, uri); const claim = selectClaimForUri(state, uri);
// TODO: eventually this should be received from DB and not local state (https://github.com/lbryio/lbry-desktop/issues/6796) // TODO: eventually this should be received from DB and not local state (https://github.com/lbryio/lbry-desktop/issues/6796)
const position = urlParams.get('t') !== null ? urlParams.get('t') : makeSelectContentPositionForUri(uri)(state); const position = urlParams.get('t') !== null ? urlParams.get('t') : selectContentPositionForUri(state, uri);
const userId = selectUser(state) && selectUser(state).id; const userId = selectUser(state) && selectUser(state).id;
const internalFeature = selectUser(state) && selectUser(state).internal_feature; const internalFeature = selectUser(state) && selectUser(state).internal_feature;
const playingUri = selectPlayingUri(state); const playingUri = selectPlayingUri(state);

View file

@ -13,7 +13,7 @@ import * as COLLECTIONS_CONSTS from 'constants/collections';
import * as SETTINGS from 'constants/settings'; import * as SETTINGS from 'constants/settings';
import { selectCostInfoForUri, doFetchCostInfoForUri } from 'lbryinc'; import { selectCostInfoForUri, doFetchCostInfoForUri } from 'lbryinc';
import { selectShowMatureContent, selectClientSetting } from 'redux/selectors/settings'; import { selectShowMatureContent, selectClientSetting } from 'redux/selectors/settings';
import { makeSelectFileRenderModeForUri, makeSelectContentPositionForUri } from 'redux/selectors/content'; import { makeSelectFileRenderModeForUri, selectContentPositionForUri } from 'redux/selectors/content';
import { selectCommentsListTitleForUri, selectSettingsByChannelId } from 'redux/selectors/comments'; import { selectCommentsListTitleForUri, selectSettingsByChannelId } from 'redux/selectors/comments';
import { DISABLE_COMMENTS_TAG } from 'constants/tags'; import { DISABLE_COMMENTS_TAG } from 'constants/tags';
import { getChannelIdFromClaim } from 'util/claim'; import { getChannelIdFromClaim } from 'util/claim';
@ -42,7 +42,7 @@ const select = (state, props) => {
isLivestream: selectIsStreamPlaceholderForUri(state, uri), isLivestream: selectIsStreamPlaceholderForUri(state, uri),
hasCollectionById: Boolean(makeSelectCollectionForId(collectionId)(state)), hasCollectionById: Boolean(makeSelectCollectionForId(collectionId)(state)),
collectionId, collectionId,
position: makeSelectContentPositionForUri(uri)(state), position: selectContentPositionForUri(state, uri),
commentsListTitle: selectCommentsListTitleForUri(state, uri), commentsListTitle: selectCommentsListTitleForUri(state, uri),
}; };
}; };

View file

@ -1,11 +1,11 @@
// @flow // @flow
import { createSelector } from 'reselect'; import { createSelector } from 'reselect';
import { import {
makeSelectClaimForUri,
selectClaimsByUri, selectClaimsByUri,
selectClaimIsNsfwForUri, selectClaimIsNsfwForUri,
selectClaimIsMineForUri, selectClaimIsMineForUri,
makeSelectContentTypeForUri, makeSelectContentTypeForUri,
selectClaimForUri,
} from 'redux/selectors/claims'; } from 'redux/selectors/claims';
import { makeSelectMediaTypeForUri, makeSelectFileNameForUri } from 'redux/selectors/file_info'; import { makeSelectMediaTypeForUri, makeSelectFileNameForUri } from 'redux/selectors/file_info';
import { selectBalance } from 'redux/selectors/wallet'; import { selectBalance } from 'redux/selectors/wallet';
@ -55,15 +55,16 @@ export const makeSelectIsPlayerFloating = (location: UrlLocation) =>
return true; return true;
}); });
export const makeSelectContentPositionForUri = (uri: string) => export const selectContentPositionForUri = (state: State, uri: string) => {
createSelector(selectState, makeSelectClaimForUri(uri), (state, claim) => { const claim = selectClaimForUri(state, uri);
if (!claim) { if (claim) {
return null;
}
const outpoint = `${claim.txid}:${claim.nout}`; const outpoint = `${claim.txid}:${claim.nout}`;
const id = claim.claim_id; const id = claim.claim_id;
return state.positions[id] ? state.positions[id][outpoint] : null; const positions = selectState(state).positions;
}); return positions[id] ? positions[id][outpoint] : null;
}
return null;
};
export const selectHistory = createSelector(selectState, (state) => state.history || []); export const selectHistory = createSelector(selectState, (state) => state.history || []);