-
Notifications
You must be signed in to change notification settings - Fork 20
homework 5 #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
homework 5 #51
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,22 @@ | ||
| import { ADD_COMMENT } from '../constants' | ||
| import {normalizedComments} from '../fixtures' | ||
| import {arrToMap} from './utils' | ||
| import { Record } from 'immutable' | ||
| import {LOAD_COMMENTS, START, SUCCESS} from "../constants/index"; | ||
|
|
||
| export default (state = arrToMap(normalizedComments), action) => { | ||
| const CommentRecord = Record({ | ||
| id: null, | ||
| user: null, | ||
| text: null, | ||
| }) | ||
|
|
||
| const ReducerState = Record({ | ||
| entities: arrToMap([], CommentRecord), | ||
| loading: false, | ||
| loaded: false, | ||
| error: null | ||
| }) | ||
|
|
||
| export default (state = new ReducerState(), action) => { | ||
| const { type, payload, randomId } = action | ||
|
|
||
| switch (type) { | ||
|
|
@@ -11,7 +25,13 @@ export default (state = arrToMap(normalizedComments), action) => { | |
| ...payload.comment, | ||
| id: randomId | ||
| }) | ||
| case LOAD_COMMENTS + START: | ||
| return state.set("loading",true) | ||
|
|
||
| case LOAD_COMMENTS + SUCCESS: | ||
| return state.update("entities",comments=>comments.merge(arrToMap(payload.response,CommentRecord))) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. .mergeIn |
||
| .set("loading",false) | ||
| .set("loaded",true) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Почему loaded === true, ведь ты загрузил только для одной статьи?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Но ведь процесс загрузки комментариев был(хоть и для одной страницы) и нужно показать что он окончен. А в article я поставил признак, загружены ли комментарии для данной страницы |
||
| default: | ||
| return state | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
здесь не достаточно повесить loading на весь comments, ведь ты для конкрентной статьи загружаешь