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) { | ||||
const reportStoreOperations: $ReadOnlyArray<ReportStoreOperation> = | |||||
convertReportsToReplaceReportOps(newReports); | |||||
const queuedReports = processReportStoreOperations( | |||||
state.queuedReports, | |||||
reportStoreOperations, | |||||
); | |||||
return { | |||||
reportStore: { | |||||
...state, | |||||
queuedReports, | |||||
}, | |||||
reportStoreOperations, | |||||
}; | |||||
} | |||||
tomek: It's quite strange that this happens outside the actions, but it follows the convention from… | |||||
kamilAuthorUnsubmitted Done Inline ActionsYeah, but it'll be hard to fix. That's because some inconsistencies are not added to store by dispatching action but directly from other reducers as reduceReportStore argument kamil: Yeah, but it'll be hard to fix. That's because some inconsistencies are not added to store by… | |||||
return { reportStore: state, reportStoreOperations: [] }; | |||||
} | } |
It's quite strange that this happens outside the actions, but it follows the convention from the original code.