import { ActionReducer, StateAction } from "../StateManager.js"; import { Action } from "../action/DataUnitAction.js"; import StateManager from "../StateManager.js"; class LoadingPropertiesImpl implements ActionReducer{ public sliceName: string = "loadingProperties"; public reduce(_stateManager:StateManager, currentState: Map, action: StateAction): Map|undefined { switch(action.type){ case Action.LOADING_PROPERTY_ADDED: return buildNewState(currentState, action.payload); case Action.LOADING_PROPERTIES_CLEANED: return undefined; } return currentState; } } export const LoadingPropertiesReducer = new LoadingPropertiesImpl(); export const getLoadingProperties = (stateManager: StateManager): Map|undefined => { return stateManager.select(LoadingPropertiesReducer.sliceName, (state: Map) => state); }; function buildNewState(currentState: Map, payload: any): Map{ const newState = new Map(currentState); if(payload != undefined){ for (const [key, value] of Object.entries(payload)) { if(typeof key === "string" && typeof value === "string"){ newState.set(key, value); } } } return newState; }