import { ActionReducer, StateAction } from "../StateManager.js"; import { Action } from "../action/DataUnitAction.js"; import StateManager from "../StateManager.js"; class RemovedRecordsReducerImpl implements ActionReducer{ public sliceName: string = "hist::removedRecords"; public reduce(_stateManager:StateManager, currentState: Array, action: StateAction): Array|undefined { switch(action.type){ case Action.RECORDS_REMOVED: const {records, buffered} = action.payload; if(buffered){ return (currentState||[]).concat(records); } return currentState; case Action.EDITION_CANCELED: case Action.DATA_SAVED: return undefined; } return currentState; } } export const RemovedRecordsReducer = new RemovedRecordsReducerImpl(); export const getRemovedRecords = (stateManager: StateManager): Array => { return stateManager.select(RemovedRecordsReducer.sliceName, (state: Array) => state); };