diff --git a/src/utils/flattenWhenNode.js b/src/utils/flattenWhenNode.js index 894d0526..95147cae 100644 --- a/src/utils/flattenWhenNode.js +++ b/src/utils/flattenWhenNode.js @@ -1,5 +1,5 @@ import isMap from 'lodash/isMap'; -import { DEFAULT_NAMESPACE } from '../constants'; +import { DEFAULT_NAMESPACE, ACTION_TYPE_DELIMITER } from '../constants'; import ownKeys from './ownKeys'; function get(key, x) { @@ -14,9 +14,12 @@ export default predicate => partialFlatActionType = '' ) { function connectNamespace(type) { - return partialFlatActionType - ? `${partialFlatActionType}${namespace}${type}` - : type; + if (!partialFlatActionType) return type; + const types = type.toString().split(ACTION_TYPE_DELIMITER); + const partials = partialFlatActionType.split(ACTION_TYPE_DELIMITER); + return [] + .concat(...partials.map(p => types.map(t => `${p}${namespace}${t}`))) + .join(ACTION_TYPE_DELIMITER); } function connectPrefix(type) { diff --git a/test/handleActions.test.js b/test/handleActions.test.js index 1da92289..208f5d7b 100644 --- a/test/handleActions.test.js +++ b/test/handleActions.test.js @@ -529,3 +529,30 @@ test('works with nested reducerMap and identity handlers', () => { message: 'hello' }); }); + +test('works with combineActions nested', () => { + const { apiCall1, apiCall2 } = createActions('API_CALL_1', 'API_CALL_2'); + const { + apiCall1: { loading: apiCallLoading1 }, + apiCall2: { loading: apiCallLoading2 } + } = createActions({ + API_CALL_1: { LOADING: undefined }, + API_CALL_2: { LOADING: undefined } + }); + + const reducer = handleActions( + { + [combineActions(apiCall1, apiCall2)]: { + LOADING: (state, { payload: loading }) => ({ loading }) + } + }, + { loading: false } + ); + + expect(reducer({ loading: false }, apiCallLoading1(true))).toEqual({ + loading: true + }); + expect(reducer({ loading: false }, apiCallLoading2(true))).toEqual({ + loading: true + }); +});