小部件组件传递给横幅的错误消息。因此,从一个客户端到另一个客户端时,相同的错误消息不会累积在横幅上。我想知道是否有一种方法可以在reducer中没有if语句的情况下实现
reducer` const clone_state = { ...state };
switch (action.type) {
case status_banner.BANNER_GETS_ERROR_MESSAGES: {
const d = action.payload;
const already_present = state.error_list.find(
element => element.message === d.message
);
if (already_present) {
return clone_state;
} else {
clone_state.error_list.push({
message_type: d.message_type,
message: d.message
});
}
return clone_state;
}`
小部件使用以下逻辑将错误消息传递到商店
store.select(fromReducers.getWidgetState).subscribe(data => {
this.widgetState = data;
if (data === fromReducersCollection.ValidWidgetStates.ERROR) {
this.store.dispatch(
new error_actions.BannerGetErrorMessage({
message_type: MessageType.ERROR,
message: WidgetNames.CD_ASSETMIX
})
);
} else {
this.store.dispatch(
new error_actions.BannerDismissesErrorMessage({
message_type: null,
message: WidgetNames.CD_ASSETMIX
})
);
}
我如何改善这一过程?