-
Notifications
You must be signed in to change notification settings - Fork 14
Hometask6 #83
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 #83
Changes from all commits
d181650
430a4e6
464d9d1
297041f
575604f
80684ed
3e97d46
bad1984
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,47 @@ | ||
| import { ADD_COMMENT } from '../constants' | ||
| import {normalizedComments} from '../fixtures' | ||
| import {arrToMap} from './utils' | ||
| import { ADD_COMMENT, LOAD_COMMENT, START, SUCCESS } from '../constants' | ||
|
|
||
| export default (state = arrToMap(normalizedComments), action) => { | ||
| const { type, payload, randomId } = action | ||
| import { arrToMap } from './utils' | ||
| import { Map, Record } from 'immutable' | ||
|
|
||
|
|
||
|
|
||
| const CommentsRecord = Record({ | ||
| id: null, | ||
| text: null, | ||
| user: null, | ||
| loading: false | ||
| }) | ||
|
|
||
| const ReducerRecord = Record({ | ||
| entities: arrToMap([], CommentsRecord), | ||
| loading: false, | ||
| loaded: false, | ||
| error: null | ||
| }) | ||
|
|
||
|
|
||
| export default (comments = new ReducerRecord(), action) => { | ||
| const { type, payload, randomId, response, error } = action | ||
|
|
||
| switch (type) { | ||
| case ADD_COMMENT: | ||
| return state.set(randomId, { | ||
| return comments.setIn(['entities', randomId], new CommentsRecord({ | ||
| ...payload.comment, | ||
| id: randomId | ||
| }) | ||
| })) | ||
|
|
||
| case LOAD_COMMENT + START: | ||
| return comments.set('loading', 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. здесь не достаточно повесить loading на весь comments, ведь ты для конкрентной статьи загружаешь |
||
|
|
||
| case LOAD_COMMENT + SUCCESS: | ||
| { | ||
| console.log(payload.response) | ||
| 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(payload.response, CommentsRecord)) | ||
|
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.
вот этого хода я совсем не осознал) зачем доставать id из коммента, чтоб потом по нему снова найти этот коммент из стора?