Flatten misc reducer

This commit is contained in:
Josh Johnson 2019-12-23 17:13:59 +00:00
parent 5694a2a651
commit ac4a1b54b9
5 changed files with 13 additions and 21 deletions

View file

@ -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,
});
});
});

View file

@ -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 => {

View file

@ -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',

View file

@ -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: {

View file

@ -120,7 +120,7 @@ export default class Store {
* Get loading state from store
*/
isLoading(): boolean {
return this.state.general.loading;
return this.state.loading;
}
/**