Skip to content

Commit 4fc00f5

Browse files
Remove lodash.reduce, lodash.camelCase (#166)
1 parent 331e7d7 commit 4fc00f5

File tree

4 files changed

+49
-4
lines changed

4 files changed

+49
-4
lines changed

src/__tests__/camelCase-test.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import camelCase from '../camelCase';
2+
import { expect } from 'chai';
3+
4+
describe('camelCase', () => {
5+
it('should camel case a conventional action type', () => {
6+
expect(camelCase('MY_ACTION')).to.equal('myAction');
7+
});
8+
9+
it('should include forward slashes in words', () => {
10+
expect(camelCase('NAMESPACE/MY_ACTION')).to.equal('namespace/myAction');
11+
});
12+
13+
it('should do nothing to an already camel-cased action type', () => {
14+
expect(camelCase('myAction')).to.equal('myAction');
15+
});
16+
});

src/__tests__/createActions-test.js

+16
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,22 @@ describe('createActions', () => {
105105
});
106106
});
107107

108+
it('should honor special delimiters in action types', () => {
109+
const { 'p/actionOne': pActionOne, 'q/actionTwo': qActionTwo } = createActions({
110+
'P/ACTION_ONE': (key, value) => ({ [key]: value }),
111+
'Q/ACTION_TWO': (first, second) => ([first, second])
112+
});
113+
114+
expect(pActionOne('value', 1)).to.deep.equal({
115+
type: 'P/ACTION_ONE',
116+
payload: { value: 1 }
117+
});
118+
expect(qActionTwo('value', 2)).to.deep.equal({
119+
type: 'Q/ACTION_TWO',
120+
payload: ['value', 2]
121+
});
122+
});
123+
108124
it('should use the identity if the payload creator is undefined in array form', () => {
109125
const { action1, action2 } = createActions({
110126
ACTION_1: [

src/camelCase.js

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/createActions.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import identity from 'lodash/identity';
2-
import camelCase from 'lodash/camelCase';
2+
import camelCase from './camelCase';
33
import isPlainObject from 'lodash/isPlainObject';
44
import isArray from 'lodash/isArray';
5-
import reduce from 'lodash/reduce';
65
import isString from 'lodash/isString';
76
import isFunction from 'lodash/isFunction';
87
import createAction from './createAction';
@@ -32,7 +31,8 @@ function isValidActionsMapValue(actionsMapValue) {
3231
}
3332

3433
function fromActionsMap(actionsMap) {
35-
return reduce(actionsMap, (actionCreatorsMap, actionsMapValue, type) => {
34+
return Object.keys(actionsMap).reduce((actionCreatorsMap, type) => {
35+
const actionsMapValue = actionsMap[type];
3636
invariant(
3737
isValidActionsMapValue(actionsMapValue),
3838
'Expected function, undefined, or array with payload and meta ' +
@@ -41,7 +41,6 @@ function fromActionsMap(actionsMap) {
4141
const actionCreator = isArray(actionsMapValue)
4242
? createAction(type, ...actionsMapValue)
4343
: createAction(type, actionsMapValue);
44-
4544
return { ...actionCreatorsMap, [camelCase(type)]: actionCreator };
4645
}, {});
4746
}

0 commit comments

Comments
 (0)