From 2aa92f15e74d98ed0cbd82c3fb86276a63f8085e Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Sat, 16 Dec 2017 21:33:38 +0000 Subject: [PATCH] Reducer: don't reset the store when fetching. There were a couple of bugs there: 1. The store was reset while fetching/error because the payload was empty/error. 2. The error status wasn't reset after for successful fetches that follow failed ones. --- src/store/reducers.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/store/reducers.ts b/src/store/reducers.ts index 8d088c3..d277ea7 100644 --- a/src/store/reducers.ts +++ b/src/store/reducers.ts @@ -67,10 +67,17 @@ function credentialsIdentityReducer(state: CredentialsType = {value: null}, acti function fetchTypeIdentityReducer( state: Record> = fetchTypeRecord()(), action: any, extend: boolean = false) { if (action.error) { - return state.set('value', null).set('error', action.payload); + return state.set('error', action.payload); } else { const fetching = (action.payload === undefined) ? true : undefined; const payload = (action.payload === undefined) ? null : action.payload; + + state = state.set('error', undefined); + + if (fetching) { + return state.set('fetching', fetching); + } + let value = state.get('value', null); if (extend && (value !== null)) { if (payload !== null) { @@ -81,7 +88,10 @@ function fetchTypeIdentityReducer( } else { value = null; } - return state.set('value', value).set('fetching', fetching); + return state.merge({ + value, + fetching, + }); } }