67 lines
No EOL
1.7 KiB
JavaScript
67 lines
No EOL
1.7 KiB
JavaScript
import { createStore } from 'redux';
|
|
|
|
const intitialState = {
|
|
user: null,
|
|
categories: null,
|
|
gateway: { isConnected: false },
|
|
messages: {},
|
|
subscribedToCategories: []
|
|
};
|
|
|
|
const reducer = (state = intitialState, payload) => {
|
|
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
|
|
]
|
|
}
|
|
}
|
|
}
|
|
|
|
case 'categories/selectcategory': {
|
|
return {
|
|
...state,
|
|
subscribedToCategories: [
|
|
...state.subscribedToCategories || [],
|
|
payload.categoryId
|
|
]
|
|
}
|
|
}
|
|
|
|
default: {
|
|
return state;
|
|
}
|
|
}
|
|
};
|
|
|
|
const store = createStore(reducer, window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__());
|
|
|
|
export default store; |