diff --git a/src/scripts/reducers/index.test.ts b/src/scripts/reducers/index.test.ts index da229ee..50e252c 100644 --- a/src/scripts/reducers/index.test.ts +++ b/src/scripts/reducers/index.test.ts @@ -4,6 +4,7 @@ import rootReducer from '.'; import groups from './groups'; import choices from './choices'; import items from './items'; +import loading from './loading'; describe('reducers/rootReducer', () => { const store = createStore(rootReducer); @@ -14,6 +15,7 @@ describe('reducers/rootReducer', () => { expect(state.groups).to.equal(groups(undefined, {} as any)); expect(state.choices).to.equal(choices(undefined, {} as any)); expect(state.items).to.equal(items(undefined, {} as any)); + expect(state.loading).to.equal(loading(undefined, {} as any)); }); describe('CLEAR_ALL', () => { @@ -33,9 +35,7 @@ describe('reducers/rootReducer', () => { items: [], groups: [], choices: [], - general: { - loading: false, - }, + loading: false, }); }); }); diff --git a/src/scripts/reducers/index.ts b/src/scripts/reducers/index.ts index d4d5c7a..92b10e4 100644 --- a/src/scripts/reducers/index.ts +++ b/src/scripts/reducers/index.ts @@ -2,23 +2,21 @@ import { combineReducers } from 'redux'; import items from './items'; import groups from './groups'; import choices from './choices'; -import general from './general'; +import loading from './loading'; import { cloneObject } from '../lib/utils'; export const defaultState = { groups: [], items: [], choices: [], - general: { - loading: false, - }, + loading: false, }; const appReducer = combineReducers({ items, groups, choices, - general, + loading, }); const rootReducer = (passedState, action): object => { diff --git a/src/scripts/reducers/general.test.ts b/src/scripts/reducers/loading.test.ts similarity index 74% rename from src/scripts/reducers/general.test.ts rename to src/scripts/reducers/loading.test.ts index 4589e8d..cbf9c4b 100644 --- a/src/scripts/reducers/general.test.ts +++ b/src/scripts/reducers/loading.test.ts @@ -1,16 +1,14 @@ import { expect } from 'chai'; -import general, { defaultState } from './general'; +import general, { defaultState } from './loading'; -describe('reducers/general', () => { +describe('reducers/loading', () => { it('should return same state when no action matches', () => { expect(general(defaultState, {} as any)).to.equal(defaultState); }); describe('SET_IS_LOADING', () => { it('sets loading state', () => { - const expectedState = { - loading: true, - }; + const expectedState = true; const actualState = general(undefined, { type: 'SET_IS_LOADING', diff --git a/src/scripts/reducers/general.ts b/src/scripts/reducers/loading.ts similarity index 71% rename from src/scripts/reducers/general.ts rename to src/scripts/reducers/loading.ts index db149e2..58f6469 100644 --- a/src/scripts/reducers/general.ts +++ b/src/scripts/reducers/loading.ts @@ -1,21 +1,17 @@ import { SetIsLoadingAction } from '../actions/misc'; import { State } from '../interfaces'; -export const defaultState = { - loading: false, -}; +export const defaultState = false; type ActionTypes = SetIsLoadingAction; const general = ( state = defaultState, action: ActionTypes, -): State['general'] => { +): State['loading'] => { switch (action.type) { case 'SET_IS_LOADING': { - return { - loading: action.isLoading, - }; + return action.isLoading; } default: { diff --git a/src/scripts/store/store.ts b/src/scripts/store/store.ts index a06cc42..cffbf51 100644 --- a/src/scripts/store/store.ts +++ b/src/scripts/store/store.ts @@ -120,7 +120,7 @@ export default class Store { * Get loading state from store */ isLoading(): boolean { - return this.state.general.loading; + return this.state.loading; } /**