Commit 545429da authored by Robert Knight's avatar Robert Knight

Remove support for array-valued store module state

All modules now use objects for their initial state, and this is a
recommended practice for extensibility, so remove support for store
modules using an array as their initial state.
parent 148aa3c6
...@@ -95,13 +95,6 @@ function createReducer(reducers) { ...@@ -95,13 +95,6 @@ function createReducer(reducers) {
return state; return state;
} }
const stateChanges = reducer(state, action); const stateChanges = reducer(state, action);
// Some modules return an array rather than an object. They need to be
// handled differently so we don't convert them to an object.
if (Array.isArray(stateChanges)) {
return stateChanges;
}
return { return {
...state, ...state,
...stateChanges, ...stateChanges,
...@@ -286,7 +279,9 @@ export function makeAction(reducers, type, payload) { ...@@ -286,7 +279,9 @@ export function makeAction(reducers, type, payload) {
* @template Actions * @template Actions
* @template {SelectorMap<State>} Selectors * @template {SelectorMap<State>} Selectors
* @template [RootSelectors={}] * @template [RootSelectors={}]
* @param {State | ((...args: any[]) => State)} initialState * @param {State | ((...args: any[]) => State)} initialState - Object containing
* the initial state for the module, or a function which returns such an
* object. The arguments come from the {@link createStore} call.
* @param {object} config * @param {object} config
* @param {string} config.namespace - * @param {string} config.namespace -
* The key under which this module's state will live in the store's root state * The key under which this module's state will live in the store's root state
......
...@@ -65,29 +65,6 @@ const counterModules = [ ...@@ -65,29 +65,6 @@ const counterModules = [
}), }),
]; ];
// Store module whose state is an array.
const tagsModule = createStoreModule([], {
namespace: 'tags',
reducers: {
ADD_TAG(state, action) {
return [...state, action.tag];
},
},
actionCreators: {
addTag(tag) {
return { type: 'ADD_TAG', tag };
},
},
selectors: {
getTags(state) {
return state;
},
},
});
// Store module with reducers that update only a subset of the state. // Store module with reducers that update only a subset of the state.
const groupsModule = createStoreModule( const groupsModule = createStoreModule(
{ {
...@@ -245,14 +222,6 @@ describe('createStore', () => { ...@@ -245,14 +222,6 @@ describe('createStore', () => {
assert.equal(store.getState().test.value, 42); assert.equal(store.getState().test.value, 42);
}); });
it('supports modules whose state is an array', () => {
const store = createStore([tagsModule]);
assert.deepEqual(store.getTags(), []);
store.addTag('tag-1');
store.addTag('tag-2');
assert.deepEqual(store.getTags(), ['tag-1', 'tag-2']);
});
it('combines state updates from reducers with initial module state', () => { it('combines state updates from reducers with initial module state', () => {
const store = createStore([groupsModule]); const store = createStore([groupsModule]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment