From 57f89e38403874ec8f56875787a58baed598b366 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Tue, 5 Dec 2017 15:36:51 +0000 Subject: [PATCH] Store: make global fetch count tracking generic. --- src/store.tsx | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/store.tsx b/src/store.tsx index 7583cb5..7797a8e 100644 --- a/src/store.tsx +++ b/src/store.tsx @@ -96,18 +96,18 @@ function credentials(state: CredentialsType = {status: FetchStatus.Initial, valu } function fetchCount(state: number = 0, action: any) { - // FIXME: Make it automatic by action properties. + if ('status' in action) { + switch (action.status) { + case FetchStatus.Request: + return state + 1; + case FetchStatus.Success: + case FetchStatus.Failure: + return state - 1; + default: + return state; + } + } switch (action.type) { - case Actions.FETCH_CREDENTIALS: - switch (action.status) { - case FetchStatus.Request: - return state + 1; - case FetchStatus.Success: - case FetchStatus.Failure: - return state - 1; - default: - return state; - } default: return state; }