Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/utils/flattenWhenNode.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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) {
Expand Down
27 changes: 27 additions & 0 deletions test/handleActions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
});