-
Notifications
You must be signed in to change notification settings - Fork 20
Hw 5 #53
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?
Hw 5 #53
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,18 +1,43 @@ | ||
| import { ADD_COMMENT } from '../constants' | ||
| import { ADD_COMMENT, LOAD_COMMENTS, START, SUCCESS } from '../constants' | ||
| import {normalizedComments} from '../fixtures' | ||
| import {arrToMap} from './utils' | ||
| import { Record } from 'immutable' | ||
|
|
||
| export default (state = arrToMap(normalizedComments), action) => { | ||
| const { type, payload, randomId } = action | ||
|
|
||
| const CommentRecord = Record({ | ||
| id: null, | ||
| user: null, | ||
| text: null | ||
| }) | ||
|
|
||
| const ReducerState = 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 | ||
| }) | ||
|
|
||
| export default (comments = new ReducerState(), action) => { | ||
| //export default (state = arrToMap(normalizedComments), action) => { | ||
| const { type, payload, response, randomId } = action | ||
|
|
||
| switch (type) { | ||
| case ADD_COMMENT: | ||
| return state.set(randomId, { | ||
| return comments.set(randomId, { | ||
| ...payload.comment, | ||
| id: randomId | ||
| }) | ||
|
|
||
| case LOAD_COMMENTS + START: | ||
| return comments.set('loading', true) | ||
|
|
||
| case LOAD_COMMENTS + SUCCESS: | ||
| console.log("bzzzzz", response) | ||
| return comments | ||
| .set('entities', arrToMap(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, ведь ты загрузил только для одной статьи? |
||
|
|
||
| default: | ||
| 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.
Если очень хочешь так делать - сделай лучше в коннекте. А вообще у нас Comment умеет достать объект по id