Skip to content

Home work 4#45

Open
jekahm wants to merge 7 commits into
romabelka:masterfrom
jekahm:home_work_4
Open

Home work 4#45
jekahm wants to merge 7 commits into
romabelka:masterfrom
jekahm:home_work_4

Conversation

@jekahm
Copy link
Copy Markdown

@jekahm jekahm commented Mar 11, 2018

No description provided.

import randomString from 'randomstring';

export const handleNewComment = (store) => (next) => (action) => {
if (action.type === ADD_NEW_COMMENT) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

через мидлвары будет проходить каждый экшин, они должны быть максимально общими, завязывать на конкретные экшины - не лучшее решение

if (action.type === ADD_NEW_COMMENT) {
let newAction = {...action};
let commentId = randomString.generate(12);
newAction.payload.data.id = commentId;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лучше не мутировать payload, мало-ли что там станут передавать

let commentId = randomString.generate(12);
newAction.payload.data.id = commentId;
let result = next(newAction);
store.dispatch(updateArticleComments(newAction.payload.articleId, commentId));
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

зачем тебе 2 диспатча?

Comment thread src/reducer/articles.js
let articlesForUpdate = {...articlesState};
let article = articlesForUpdate[payload.articleId];
if (!article.comments) {
article.comments = [];
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не мутируй стейт

Comment thread src/reducer/articles.js
if (!article.comments) {
article.comments = [];
}
article.comments.push(payload.commentId);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

и здесь не мутируй

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants