-
Notifications
You must be signed in to change notification settings - Fork 17
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
ht3 #30
base: master
Are you sure you want to change the base?
ht3 #30
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export const INCREMENT = 'INCREMENT' | ||
|
||
export const DELETE_ARTICLE = 'DELETE_ARTICLE' | ||
|
||
export const FILTER_SELECT = 'FILTER_SELECT' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,50 @@ | ||
import defaultArticles from '../fixtures' | ||
import { DELETE_ARTICLE } from '../constants' | ||
import { DELETE_ARTICLE, FILTER_SELECT } from '../constants' | ||
|
||
export default (articlesState = defaultArticles, action) => { | ||
export default ( | ||
articleObj = { | ||
articlesState: defaultArticles, | ||
articlesVisable: {}, | ||
articlesFilter: {} | ||
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. Лучше храни отдельно статьи и отдельно значения фильтров. Саму фильтрацию можешь потом сделать в коннекте, при необходимости. Старайся хранить минимальное состояние в сторе. Все, что можно посчитать - считай там, где это нужно |
||
}, | ||
action | ||
) => { | ||
const { type, payload } = action | ||
|
||
switch (type) { | ||
case DELETE_ARTICLE: | ||
return articlesState.filter((article) => article.id !== payload.id) | ||
case DELETE_ARTICLE: { | ||
let item_article = articleObj.articlesState.filter( | ||
(article) => article.id !== payload.id | ||
) | ||
let item_visable = articleObj.articlesVisable.filter( | ||
(article) => article.id !== payload.id | ||
) | ||
let item_filter = articleObj.articlesFilter.filter( | ||
(article) => article.value !== payload.id | ||
) | ||
articleObj = { | ||
...articleObj, | ||
articlesState: item_article, | ||
articlesVisable: item_visable, | ||
articlesFilter: item_filter | ||
} | ||
return articleObj | ||
} | ||
|
||
case FILTER_SELECT: { | ||
let item_id = new Set(payload.select.selected.map((item) => item.value)) | ||
let item_visable = articleObj.articlesState.filter((article) => | ||
item_id.has(article.id) | ||
) | ||
articleObj = { | ||
...articleObj, | ||
articlesVisable: item_visable, | ||
articlesFilter: payload.select.selected | ||
} | ||
return articleObj | ||
} | ||
|
||
default: | ||
return articlesState | ||
return articleObj | ||
} | ||
} |
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.
Лучше храни отдельно статьи и отдельно значения фильтров. Саму фильтрацию можешь потом сделать в коннекте, при необходимости. Старайся хранить минимальное состояние в сторе. Все, что можно посчитать - считай там, где это нужно