Skip to content

homework4#47

Open
MrBlackD wants to merge 1 commit into
romabelka:masterfrom
MrBlackD:home-work-4
Open

homework4#47
MrBlackD wants to merge 1 commit into
romabelka:masterfrom
MrBlackD:home-work-4

Conversation

@MrBlackD
Copy link
Copy Markdown

No description provided.

export default connect(state => ({
selected: state.filters.selected,
articles: state.articles
articles: Object.values(state.articles)
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.

Сделай селектор

import {ADD_COMMENT} from "../constants/index";

export default store => next => action => {
if(action.type === ADD_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.

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


export default store => next => action => {
if(action.type === ADD_COMMENT) {
action.payload.newCommentId = Math.random().toString(36).slice(2);
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, мало-ли что там станут передавать

Comment thread src/reducer/articles.js

const {articleId,newCommentId} = action.payload;
const article = {...articlesState[articleId]}
article.comments.push(newCommentId)
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