canape/frontend/js/reducers/notifications.js
Grégoire Delattre 4b26080193
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
Update redux state management
Use immer with native javascript objects instead of immutablejs.
2020-04-07 18:22:26 +02:00

25 lines
511 B
JavaScript

import { produce } from "immer";
const defaultState = new Map();
export default (state = defaultState, action) =>
produce(state, (draft) => {
switch (action.type) {
case "ADD_NOTIFICATION": {
let id = Math.random().toString(36).substring(7);
draft.set(id, {
id: id,
...action.payload,
});
break;
}
case "REMOVE_NOTIFICATION":
draft.delete(action.payload.id);
break;
default:
return draft;
}
});