-
Notifications
You must be signed in to change notification settings - Fork 14
Hometask6 #79
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 #79
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,16 +1,38 @@ | ||
| import { ADD_COMMENT } from '../constants' | ||
| import {normalizedComments} from '../fixtures' | ||
| import { Record } from 'immutable' | ||
| import { ADD_COMMENT, LOAD_COMMENTS, START, SUCCESS } from '../constants' | ||
| import {arrToMap} from './utils' | ||
|
|
||
| export default (state = arrToMap(normalizedComments), action) => { | ||
| const commentRecord = Record({ | ||
| id: null, | ||
| user: null, | ||
| text: null | ||
| }) | ||
|
|
||
| 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, | ||
| articleID: null, | ||
| }) | ||
|
|
||
| export default (state = new ReducerRecord(), action) => { | ||
| const { type, payload, randomId } = action | ||
|
|
||
| switch (type) { | ||
| case ADD_COMMENT: | ||
| return state.set(randomId, { | ||
| ...payload.comment, | ||
| id: randomId | ||
| }) | ||
| return state.setIn(['entities', randomId], new commentRecord({ ...payload.comment, id: randomId})) | ||
|
|
||
| case LOAD_COMMENTS + START: | ||
| return state | ||
| .set('loading', true) | ||
| .set('articleID', payload.id) | ||
|
|
||
| case LOAD_COMMENTS + SUCCESS: | ||
| return state | ||
| .set('entities', 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, ведь ты загрузил только для одной статьи? |
||
| } | ||
|
|
||
| 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.
не понял. Зачем ты достаешь id, чтоб потом сразу же по этому id искать этот же коммент в сторе?