|
@@ -1,7 +1,6 @@
|
|
|
-const ADD_POST = 'ADD-POST';
|
|
|
-const UPDATE_NEW_POST_TEXT = 'UPDATE-NEW-POST-TEXT';
|
|
|
-const UPDATE_NEW_MESSAGE_BODY = 'UPDATE-NEW-MESSAGE-BODY';
|
|
|
-const SEND_MESSAGE = 'SEND-MESSAGE';
|
|
|
+import messagesReducer from "./messages-reducer";
|
|
|
+import navbarReducer from "./navbar-reducer";
|
|
|
+import profileReducer from "./profile-reducer";
|
|
|
|
|
|
let store = {
|
|
|
_state: {
|
|
@@ -29,6 +28,7 @@ let store = {
|
|
|
],
|
|
|
newMessageBody: ""
|
|
|
},
|
|
|
+ navbar: {}
|
|
|
},
|
|
|
getState() {
|
|
|
return this._state;
|
|
@@ -37,44 +37,13 @@ let store = {
|
|
|
this._callSubscriber = observer;
|
|
|
},
|
|
|
dispatch(action) {
|
|
|
- if (action.type === ADD_POST) {
|
|
|
- let newPost = {
|
|
|
- id: 5,
|
|
|
- message: this._state.profilePage.newPostText,
|
|
|
- likesCount: 0,
|
|
|
- };
|
|
|
- this._state.profilePage.post.push(newPost);
|
|
|
- this._state.profilePage.newPostText = "";
|
|
|
- this._callSubscriber(this._state);
|
|
|
- } else if(action.type === UPDATE_NEW_POST_TEXT) {
|
|
|
- this._state.profilePage.newPostText = action.newText;
|
|
|
- this._callSubscriber(this._state);
|
|
|
- } else if(action.type === UPDATE_NEW_MESSAGE_BODY) {
|
|
|
- this._state.messagesPage.newMessageBody = action.body;
|
|
|
- this._callSubscriber(this._state);
|
|
|
- } else if(action.type === SEND_MESSAGE) {
|
|
|
- let body = this._state.messagesPage.newMessageBody;
|
|
|
- this._state.messagesPage.newMessageBody = 0;
|
|
|
- this._state.messagesPage.messagesData.push({ id: 4, message: body });
|
|
|
- this._callSubscriber(this._state);
|
|
|
- }
|
|
|
- }
|
|
|
-};
|
|
|
|
|
|
-export const addPostActionCreator = (body) => ({ type: 'ADD-POST', body });
|
|
|
-export const updateNewPostTextActionCreator = (text) => {
|
|
|
- return {
|
|
|
- type: 'UPDATE-NEW-POST-TEXT',
|
|
|
- newText: text
|
|
|
- }
|
|
|
-}
|
|
|
+ this._state.profilePage = profileReducer(this._state.profilePage, action)
|
|
|
+ this._state.messagesPage = messagesReducer(this._state.messagesPage, action)
|
|
|
+ this._state.navbar = navbarReducer(this._state.navbar, action)
|
|
|
|
|
|
-export const sendMessageCreator = () => ({ type: 'SEND-MESSAGE' });
|
|
|
-export const updateNewMessageBodyCreator = (body) => {
|
|
|
- return {
|
|
|
- type: 'UPDATE-NEW-MESSAGE-BODY',
|
|
|
- body: body
|
|
|
+ this._callSubscriber(this._state);
|
|
|
}
|
|
|
-}
|
|
|
+};
|
|
|
|
|
|
export default store;
|