Improve selectors in PageConnector to reduce re-rendering

This commit is contained in:
Mark McDowall 2019-04-06 22:02:47 -07:00
parent 8f3dbbc356
commit b40d7d89a1
2 changed files with 100 additions and 45 deletions

View File

@ -12,7 +12,8 @@ function ErrorPage(props) {
tagsError,
qualityProfilesError,
languageProfilesError,
uiSettingsError
uiSettingsError,
systemStatusError
} = props;
let errorMessage = 'Failed to load Sonarr';
@ -31,6 +32,8 @@ function ErrorPage(props) {
errorMessage = getErrorMessage(languageProfilesError, 'Failed to load language profiles from API');
} else if (uiSettingsError) {
errorMessage = getErrorMessage(uiSettingsError, 'Failed to load UI settings from API');
} else if (systemStatusError) {
errorMessage = getErrorMessage(uiSettingsError, 'Failed to load system status from API');
}
return (
@ -54,7 +57,8 @@ ErrorPage.propTypes = {
tagsError: PropTypes.object,
qualityProfilesError: PropTypes.object,
languageProfilesError: PropTypes.object,
uiSettingsError: PropTypes.object
uiSettingsError: PropTypes.object,
systemStatusError: PropTypes.object
};
export default ErrorPage;

View File

@ -27,59 +27,110 @@ function testLocalStorage() {
}
}
function createMapStateToProps() {
return createSelector(
(state) => state.series,
(state) => state.customFilters,
(state) => state.tags,
(state) => state.settings.ui,
(state) => state.settings.qualityProfiles,
(state) => state.settings.languageProfiles,
(state) => state.app,
createDimensionsSelector(),
(
series,
customFilters,
tags,
uiSettings,
qualityProfiles,
languageProfiles,
app,
dimensions
) => {
const isPopulated = (
series.isPopulated &&
customFilters.isPopulated &&
tags.isPopulated &&
qualityProfiles.isPopulated &&
languageProfiles.isPopulated &&
uiSettings.isPopulated
);
const selectAppProps = createSelector(
(state) => state.app.isSidebarVisible,
(state) => state.app.version,
(state) => state.app.isUpdated,
(state) => state.app.isDisconnected,
(isSidebarVisible, version, isUpdated, isDisconnected) => {
return {
isSidebarVisible,
version,
isUpdated,
isDisconnected
};
}
);
const selectIsPopulated = createSelector(
(state) => state.series.isPopulated,
(state) => state.customFilters.isPopulated,
(state) => state.tags.isPopulated,
(state) => state.settings.ui.isPopulated,
(state) => state.settings.qualityProfiles.isPopulated,
(state) => state.settings.languageProfiles.isPopulated,
(state) => state.system.status.isPopulated,
(
seriesIsPopulated,
customFiltersIsPopulated,
tagsIsPopulated,
uiSettingsIsPopulated,
qualityProfilesIsPopulated,
languageProfilesIsPopulated,
systemStatusIsPopulated
) => {
return (
seriesIsPopulated &&
customFiltersIsPopulated &&
tagsIsPopulated &&
uiSettingsIsPopulated &&
qualityProfilesIsPopulated &&
languageProfilesIsPopulated &&
systemStatusIsPopulated
);
}
);
const selectErrors = createSelector(
(state) => state.series.error,
(state) => state.customFilters.error,
(state) => state.tags.error,
(state) => state.settings.ui.error,
(state) => state.settings.qualityProfiles.error,
(state) => state.settings.languageProfiles.error,
(state) => state.system.status.error,
(
seriesError,
customFiltersError,
tagsError,
uiSettingsError,
qualityProfilesError,
languageProfilesError,
systemStatusError
) => {
const hasError = !!(
series.error ||
customFilters.error ||
tags.error ||
qualityProfiles.error ||
languageProfiles.error ||
uiSettings.error
seriesError ||
customFiltersError ||
tagsError ||
uiSettingsError ||
qualityProfilesError ||
languageProfilesError ||
systemStatusError
);
return {
isPopulated,
hasError,
seriesError: series.error,
customFiltersError: tags.error,
tagsError: tags.error,
qualityProfilesError: qualityProfiles.error,
languageProfilesError: languageProfiles.error,
uiSettingsError: uiSettings.error,
seriesError,
customFiltersError,
tagsError,
uiSettingsError,
qualityProfilesError,
languageProfilesError,
systemStatusError
};
}
);
function createMapStateToProps() {
return createSelector(
(state) => state.settings.ui.item.enableColorImpairedMode,
selectIsPopulated,
selectErrors,
selectAppProps,
createDimensionsSelector(),
(
enableColorImpairedMode,
isPopulated,
errors,
app,
dimensions
) => {
return {
...app,
...errors,
isPopulated,
isSmallScreen: dimensions.isSmallScreen,
isSidebarVisible: app.isSidebarVisible,
enableColorImpairedMode: uiSettings.item.enableColorImpairedMode,
version: app.version,
isUpdated: app.isUpdated,
isDisconnected: app.isDisconnected
enableColorImpairedMode
};
}
);