Changeset View
Changeset View
Standalone View
Standalone View
lib/reducers/report-store-reducer.js
Show All 37 Lines | |||||
): { | ): { | ||||
reportStore: ReportStore, | reportStore: ReportStore, | ||||
reportStoreOperations: $ReadOnlyArray<ReportStoreOperation>, | reportStoreOperations: $ReadOnlyArray<ReportStoreOperation>, | ||||
} { | } { | ||||
const newReports = newInconsistencies.filter(report => | const newReports = newInconsistencies.filter(report => | ||||
isReportEnabled(report, state.enabledReports), | isReportEnabled(report, state.enabledReports), | ||||
); | ); | ||||
const updatedReports = | |||||
newInconsistencies.length > 0 | |||||
? [...state.queuedReports, ...newInconsistencies].filter(report => | |||||
isReportEnabled(report, state.enabledReports), | |||||
) | |||||
: state.queuedReports; | |||||
if (action.type === updateReportsEnabledActionType) { | if (action.type === updateReportsEnabledActionType) { | ||||
const newEnabledReports = { ...state.enabledReports, ...action.payload }; | const newEnabledReports = { ...state.enabledReports, ...action.payload }; | ||||
const newFilteredReports = newReports.filter(report => | const newFilteredReports = newReports.filter(report => | ||||
isReportEnabled(report, newEnabledReports), | isReportEnabled(report, newEnabledReports), | ||||
); | ); | ||||
const reportsToRemove = state.queuedReports.filter( | const reportsToRemove = state.queuedReports.filter( | ||||
report => !isReportEnabled(report, newEnabledReports), | report => !isReportEnabled(report, newEnabledReports), | ||||
); | ); | ||||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | ) { | ||||
return { | return { | ||||
reportStore: { | reportStore: { | ||||
...state, | ...state, | ||||
queuedReports, | queuedReports, | ||||
}, | }, | ||||
reportStoreOperations, | reportStoreOperations, | ||||
}; | }; | ||||
} | } | ||||
const reportStore = | |||||
updatedReports !== state.queuedReports | |||||
? { ...state, queuedReports: updatedReports } | |||||
: state; | |||||
return { reportStore, reportStoreOperations: [] }; | if (newReports) { | ||||
ashoat: I think this check should've been `newReports.length > 0`. As a result, we end up changing… | |||||
const reportStoreOperations: $ReadOnlyArray<ReportStoreOperation> = | |||||
convertReportsToReplaceReportOps(newReports); | |||||
const queuedReports = processReportStoreOperations( | |||||
state.queuedReports, | |||||
reportStoreOperations, | |||||
); | |||||
return { | |||||
reportStore: { | |||||
...state, | |||||
queuedReports, | |||||
}, | |||||
reportStoreOperations, | |||||
}; | |||||
} | |||||
return { reportStore: state, reportStoreOperations: [] }; | |||||
} | } |
I think this check should've been newReports.length > 0. As a result, we end up changing reportStore on every since action. Looking at the code, this shouldn't have a very negative effect (I don't think it causes any components to rerender, since processReportStoreOperations keeps state.queuedReports if reportStoreOperations is empty). However, it is causing ENG-5694