Fixed: Faster movie selector

pull/6/head
ta264 5 years ago committed by Qstick
parent e45f788ca5
commit 963c832241

@ -42,6 +42,7 @@ export default function createHandleActions(handlers, defaultState, section) {
if (_.isArray(payload.data)) { if (_.isArray(payload.data)) {
newState.items = payload.data; newState.items = payload.data;
newState.itemMap = _.zipObject(_.map(payload.data, 'id'), _.range(payload.data.length));
} else { } else {
newState.item = payload.data; newState.item = payload.data;
} }
@ -75,6 +76,7 @@ export default function createHandleActions(handlers, defaultState, section) {
newState.items.splice(index, 1, { ...item, ...otherProps }); newState.items.splice(index, 1, { ...item, ...otherProps });
} else if (!updateOnly) { } else if (!updateOnly) {
newState.items.push({ ...otherProps }); newState.items.push({ ...otherProps });
newState.itemMap = _.zipObject(_.map(newState.items, 'id'), _.range(newState.items.length));
} }
return updateSectionState(state, payloadSection, newState); return updateSectionState(state, payloadSection, newState);
@ -111,6 +113,8 @@ export default function createHandleActions(handlers, defaultState, section) {
newState.items = [...newState.items]; newState.items = [...newState.items];
_.remove(newState.items, { id: payload.id }); _.remove(newState.items, { id: payload.id });
newState.itemMap = _.zipObject(_.map(newState.items, 'id'), _.range(newState.items.length));
return updateSectionState(state, payloadSection, newState); return updateSectionState(state, payloadSection, newState);
} }

@ -1,12 +1,12 @@
import { createSelector } from 'reselect'; import { createSelector } from 'reselect';
import createAllArtistSelector from './createAllArtistSelector';
function createArtistSelector() { function createArtistSelector() {
return createSelector( return createSelector(
(state, { artistId }) => artistId, (state, { artistId }) => artistId,
createAllArtistSelector(), (state) => state.artist.itemMap,
(artistId, allArtists) => { (state) => state.artist.items,
return allArtists.find((artist) => artist.id === artistId ); (artistId, itemMap, allArtists) => {
return allArtists[itemMap[artistId]];
} }
); );
} }

Loading…
Cancel
Save