mirror of
https://github.com/Choices-js/Choices.git
synced 2024-06-15 20:25:18 +02:00
Flatten misc reducer
This commit is contained in:
parent
5694a2a651
commit
ac4a1b54b9
|
@ -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,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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 => {
|
||||
|
|
|
@ -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',
|
|
@ -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: {
|
|
@ -120,7 +120,7 @@ export default class Store {
|
|||
* Get loading state from store
|
||||
*/
|
||||
isLoading(): boolean {
|
||||
return this.state.general.loading;
|
||||
return this.state.loading;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue