From 448b847d7da56149d82bd566a200b85ca567c0ad Mon Sep 17 00:00:00 2001 From: "N.Kirilenko" Date: Mon, 24 Sep 2018 12:56:18 +0400 Subject: [PATCH 1/2] Fixed sml bug of reducer --- src/reducers/articleList.js | 17 +++++++++-------- src/reducers/home.js | 3 ++- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/reducers/articleList.js b/src/reducers/articleList.js index 1fe962daa..276401fa5 100644 --- a/src/reducers/articleList.js +++ b/src/reducers/articleList.js @@ -13,6 +13,7 @@ import { } from '../constants/actionTypes'; export default (state = {}, action) => { + if (!action.payload) return state; switch (action.type) { case ARTICLE_FAVORITED: case ARTICLE_UNFAVORITED: @@ -32,7 +33,7 @@ export default (state = {}, action) => { case SET_PAGE: return { ...state, - articles: action.payload.articles, + articles: action.payload.articles || [], articlesCount: action.payload.articlesCount, currentPage: action.page }; @@ -40,7 +41,7 @@ export default (state = {}, action) => { return { ...state, pager: action.pager, - articles: action.payload.articles, + articles: action.payload.articles || [], articlesCount: action.payload.articlesCount, tab: null, tag: action.tag, @@ -50,9 +51,9 @@ export default (state = {}, action) => { return { ...state, pager: action.pager, - tags: action.payload[0].tags, - articles: action.payload[1].articles, - articlesCount: action.payload[1].articlesCount, + tags: (!!action.payload[0] && action.payload[0].tags) || [], + articles: (!!action.payload[1] && action.payload[1].articles) || [], + articlesCount: !!action.payload[1] && action.payload[1].articlesCount, currentPage: 0, tab: action.tab }; @@ -62,7 +63,7 @@ export default (state = {}, action) => { return { ...state, pager: action.pager, - articles: action.payload.articles, + articles: action.payload.articles || [], articlesCount: action.payload.articlesCount, tab: action.tab, currentPage: 0, @@ -73,8 +74,8 @@ export default (state = {}, action) => { return { ...state, pager: action.pager, - articles: action.payload[1].articles, - articlesCount: action.payload[1].articlesCount, + articles: (!!action.payload[1] && action.payload[1].articles) || [], + articlesCount: !!action.payload[1] && action.payload[1].articlesCount, currentPage: 0 }; case PROFILE_PAGE_UNLOADED: diff --git a/src/reducers/home.js b/src/reducers/home.js index c1cd49af1..3925dee55 100644 --- a/src/reducers/home.js +++ b/src/reducers/home.js @@ -1,11 +1,12 @@ import { HOME_PAGE_LOADED, HOME_PAGE_UNLOADED } from '../constants/actionTypes'; export default (state = {}, action) => { + if (!action.payload) return state; switch (action.type) { case HOME_PAGE_LOADED: return { ...state, - tags: action.payload[0].tags + tags: (!!action.payload[0] && action.payload[0].tags) || [] }; case HOME_PAGE_UNLOADED: return {}; From 4f5a8a560c8525097d0786abd3774e494aa017c8 Mon Sep 17 00:00:00 2001 From: "N.Kirilenko" Date: Mon, 24 Sep 2018 16:38:53 +0400 Subject: [PATCH 2/2] Fixed sml bug of reducer --- src/reducers/auth.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/reducers/auth.js b/src/reducers/auth.js index 6e8383866..e32b23c46 100644 --- a/src/reducers/auth.js +++ b/src/reducers/auth.js @@ -11,6 +11,7 @@ export default (state = {}, action) => { switch (action.type) { case LOGIN: case REGISTER: + if (!action.payload) return state; return { ...state, inProgress: false,