Is your feature request related to a problem? Please describe.
The StateManager returned by an EventReceiver's receiver provides methods to both get and set state. Currently, the value returned from getState function can be used to modify the state directly, which is likely unintended behavior. This issue might also exist in other parts of Eventrix.
// tasks.ts
const markAsDoneReceiver = new EventsReceiver(MARK_TASK_AS_DONE_EVENT_NAME, (eventName, { id }, stateManager) => {
const tasks = stateManager.getState('tasks');
const taskIndex = findIndex(tasks, (task) => task.id === id);
const task = stateManager.getState(`tasks.${taskIndex}`);
task.status = 'done';
});
Describe the solution you'd like
To prevent unintended state modifications, the getState function should always return a deep copy of the relevant part of the store. This ensures that any changes made to the returned state do not affect the underlying store. (maybe using https://lodash.com/docs/4.17.15#cloneDeep)
Is your feature request related to a problem? Please describe.
The
StateManagerreturned by anEventReceiver's receiver provides methods to both get and set state. Currently, the value returned fromgetStatefunction can be used to modify the state directly, which is likely unintended behavior. This issue might also exist in other parts of Eventrix.Describe the solution you'd like
To prevent unintended state modifications, the
getStatefunction should always return a deep copy of the relevant part of the store. This ensures that any changes made to the returned state do not affect the underlying store. (maybe using https://lodash.com/docs/4.17.15#cloneDeep)