The following code is a ngrx 4 reducer could you make it compatible for ngrx 16 so it…
- User
The following code is a ngrx 4 reducer could you make it compatible for ngrx 16 so it works with createReducer()
export function reducer(state = initialState, action): State { switch (action.type) { case actions.ActionTypes.GET_TRANSPORTSTREAMS_AND_SERVICES_SUCCESS: return { ...state, sdtTsAndLogicalServicesMap: action.payload };
codecase actions.ActionTypes.GET_TRANSPORTSTREAMS_AND_SERVICES_FAILED: { let messages = [{ severity: 'error', summary: 'Failed to load logical services', detail: action.payload }]; return { ...state, messages: messages, }; } case actions.ActionTypes.GET_PID32: return { ...state, pid32: null, isLoading: true, }; case actions.ActionTypes.GET_PID32_SUCCESS: return { ...state, pid32: action.payload, isLoading: false, }; case actions.ActionTypes.GET_PID32_FAILED: let messages = [{ severity: 'error', summary: 'Failed to perform action', detail: action.payload }]; return { ...state, messages: messages, // selectedNitTable: null, TODO isLoading: false, }; case actions.ActionTypes.UPDATE_ALL_PID32: case actions.ActionTypes.UPDATE_PID32: return { ...state, isSaving: true, }; case actions.ActionTypes.UPDATE_PID32_SUCCESS: return { ...state, pid32: action.payload, isSaving: false, messages: [{ severity: 'success', summary: 'Info Message', detail: 'Injector successfully updated' }] }; case actions.ActionTypes.UPDATE_PID32_FAILED: return { ...state, isSaving: false, messages: [{ severity: 'error', summary: 'Failed update action', detail: action.payload }], }; case actions.ActionTypes.UPDATE_ALL_PID32_SUCCESS: const overridedPayload: OverridedPid32 = action.payload; const overridedStr = overridedPayload.overrided.map(pid32 => pid32.injectorId).join('\n, '); const pid32: Pid32 = overridedPayload.pid32; const detail = 'Updated injectors ' + pid32.injectorId + ', ' + overridedStr; return { ...state, pid32, isSaving: false, messages: [{ severity: 'success', summary: 'Injector successfully updated', detail }] }; case actions.ActionTypes.UPDATE_ALL_PID32_FAILED: return { ...state, isSaving: false, messages: [{ severity: 'error', summary: 'Failed to update pid32', detail: action.payload }], }; case actions.ActionTypes.UNSELECT_PID32: return { ...state, pid32: null, }; default: return state; - Assistant
- User
- Assistant
- User
The following code is a ngrx 4 reducer could you make it compatible for ngrx 16 so it works with createReducer()
export function reducer(state = initialState, action: schedule.Actions | descriptor.Actions): State { switch (action.type) { case schedule.ActionTypes.REQUEST_EVENT_DETAIL: return Object.assign({}, state, { isLoading: true, event: action.payload, });
codecase schedule.ActionTypes.REQUEST_EVENT_DETAIL_FAIL: return Object.assign({}, state, { isLoading: false, }); case schedule.ActionTypes.REQUEST_EVENT_DETAIL_SUCCESS: return Object.assign({}, state, { isLoading: false, event: action.payload.detail, descriptors: action.payload.descriptorsMap }); case schedule.ActionTypes.UNSELECT_EVENT: return Object.assign({}, state, { event: null, descriptors: null }); default: return state;} }
- Assistant
import { createReducer, on } from "@ngrx/store"; import * as schedule from "./schedule.actions"; import * as descriptor from "./descriptor.actions";
export const initialState: State = { isLoading: false, event: null, descriptors: null, };
export const reducer = createReducer( initialState, on(schedule.requestEventDetail, (state, { payload }) => ({ ...state, isLoading: true, event: payload, })), on(schedule.requestEventDetailFail, (state) => ({ ...state, isLoading: false, })), on(schedule.requestEventDetailSuccess, (state, { payload }) => ({ ...state, isLoading: false, event: payload.detail, descriptors: payload.descriptorsMap, })), on(schedule.unselectEvent, (state) => ({ ...state, event: null, descriptors: null, })) // Add cases for other action types from descriptor.Actions if needed );
- User
The following code is a ngrx 4 reducer could you make it compatible for ngrx 16 so it works with createReducer()
export function reducer(state = initialState, action: schedule.Actions | descriptor.Actions): State { switch (action.type) { case schedule.ActionTypes.SELECT_SERVICE: return Object.assign({}, state, { service: action.payload, });
codecase schedule.ActionTypes.UNSELECT_SERVICE: return Object.assign({}, state, { service: null, }); case schedule.ActionTypes.UPDATE_SERVICE_FAIL: return Object.assign({}, state, { service: null, messages: [{ severity: 'error', summary: 'Failed to update service', detail: `Updated service ${action.payload.id} failed` }] }); case schedule.ActionTypes.UPDATE_SERVICE_SUCCESS: return Object.assign({}, state, { service: null, messages: [{ severity: 'success', summary: 'Updated service', detail: `Updated service ${action.payload.id}` }] }); default: return state; - Assistant
import { createReducer, on } from "@ngrx/store"; import * as schedule from "./schedule.actions"; import * as descriptor from "./descriptor.actions";
export const initialState: State = { service: null, messages: [], };
export const reducer = createReducer( initialState, on(schedule.selectService, (state, { payload }) => ({ ...state, service: payload, })), on(schedule.unselectService, (state) => ({ ...state, service: null, })), on(schedule.updateServiceFail, (state, { payload }) => ({ ...state, service: null, messages: [ { severity: "error", summary: "Failed to update service", detail:
Updated service ${payload.id} failed, }, ], })), on(schedule.updateServiceSuccess, (state, { payload }) => ({ ...state, service: null, messages: [ { severity: "success", summary: "Updated service", detail:Updated service ${payload.id}, }, ], })) // Add cases for other action types from descriptor.Actions if needed );