-
Notifications
You must be signed in to change notification settings - Fork 14
Hometask6 #81
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?
Hometask6 #81
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,17 +1,49 @@ | ||
| import { ADD_COMMENT } from '../constants' | ||
| import { ADD_COMMENT, LOAD_ALL_COMMENTS, START, FAIL, SUCCESS } from '../constants' | ||
| import {Record} from 'immutable' | ||
| import {normalizedComments} from '../fixtures' | ||
| import {arrToMap} from './utils' | ||
|
|
||
| export default (state = arrToMap(normalizedComments), action) => { | ||
| const { type, payload, randomId } = action | ||
| const CommentRecord = Record({ | ||
| id: null, | ||
| text: null, | ||
| author: null, | ||
| loading: true, | ||
| }) | ||
|
|
||
| const ReducerRecord = Record({ | ||
| entities: arrToMap([], CommentRecord), | ||
| loading: false, | ||
|
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. здесь не достаточно повесить loading на весь comments, ведь ты для конкрентной статьи загружаешь |
||
| loaded: false, | ||
| error: null | ||
| }) | ||
|
|
||
| // export default (comments = arrToMap(normalizedComments), action) => { | ||
| export default (comments = new ReducerRecord(), action) => { | ||
| const { type, payload, randomId, response, error } = action | ||
|
|
||
| switch (type) { | ||
| case ADD_COMMENT: | ||
| return state.set(randomId, { | ||
| return comments.set(randomId, { | ||
| ...payload.comment, | ||
| id: randomId | ||
| }) | ||
|
|
||
| case LOAD_ALL_COMMENTS + START: | ||
| return comments | ||
| .set('loading', true) | ||
| .set('loaded', false) | ||
|
|
||
| case LOAD_ALL_COMMENTS + FAIL: | ||
| return comments | ||
| .set('loading', false) | ||
| .set('error', error) | ||
|
|
||
| case LOAD_ALL_COMMENTS + SUCCESS: | ||
| return comments | ||
| .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, ведь ты загрузил только для одной статьи? |
||
| .set('entities', arrToMap(response, CommentRecord)); | ||
|
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. Я думаю, что здесь я возвращаю неправильный объект, т.к. у меня все комментарии оказываются в entities.
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 |
||
| } | ||
|
|
||
| return state | ||
| return comments | ||
| } | ||
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.
сделай для этого селектор, старайся не завязываться в компонентах на api immutable