brainlet-react/bfrontend/src/store.js

56 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-12-29 22:55:53 +02:00
import { createStore } from 'redux';
const intitialState = {
user: null,
categories: null,
gateway: { isConnected: false },
messages: {}
};
const reducer = (state = intitialState, payload) => {
2020-12-29 22:55:53 +02:00
switch (payload.type) {
case 'authenticator/updatelocaluserobject': {
return {
...state,
user: payload.user
}
}
case 'categories/updatecategorylist': {
return {
...state,
categories: payload.categories
}
}
case 'gateway/connectionstatus': {
return {
...state,
gateway: {
isConnected: payload.gateway.isConnected
}
}
}
case 'messagestore/addmessage': {
return {
...state,
messages: {
...state.messages,
[payload.message.category._id]: [
...state.messages[payload.message.category._id] || [],
payload.message
]
}
}
}
2020-12-29 22:55:53 +02:00
default: {
return state;
}
}
};
const store = createStore(reducer, window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__());
export default store;