Skip to content

Remove lodash.reduce, lodash.camelCase #166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jan 26, 2017
16 changes: 16 additions & 0 deletions src/__tests__/camelCase-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import camelCase from '../camelCase';
import { expect } from 'chai';

describe('camelCase', () => {
it('should camel case a conventional action type', () => {
expect(camelCase('MY_ACTION')).to.equal('myAction');
});

it('should include forward slashes in words', () => {
expect(camelCase('NAMESPACE/MY_ACTION')).to.equal('namespace/myAction');
});

it('should do nothing to an already camel-cased action type', () => {
expect(camelCase('myAction')).to.equal('myAction');
});
});
16 changes: 16 additions & 0 deletions src/__tests__/createActions-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,22 @@ describe('createActions', () => {
});
});

it('should honor special delimiters in action types', () => {
const { 'p/actionOne': pActionOne, 'q/actionTwo': qActionTwo } = createActions({
'P/ACTION_ONE': (key, value) => ({ [key]: value }),
'Q/ACTION_TWO': (first, second) => ([first, second])
});

expect(pActionOne('value', 1)).to.deep.equal({
type: 'P/ACTION_ONE',
payload: { value: 1 }
});
expect(qActionTwo('value', 2)).to.deep.equal({
type: 'Q/ACTION_TWO',
payload: ['value', 2]
});
});

it('should use the identity if the payload creator is undefined in array form', () => {
const { action1, action2 } = createActions({
ACTION_1: [
Expand Down
14 changes: 14 additions & 0 deletions src/camelCase.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions src/createActions.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import identity from 'lodash/identity';
import camelCase from 'lodash/camelCase';
import camelCase from './camelCase';
import isPlainObject from 'lodash/isPlainObject';
import isArray from 'lodash/isArray';
import reduce from 'lodash/reduce';
import isString from 'lodash/isString';
import isFunction from 'lodash/isFunction';
import createAction from './createAction';
Expand Down Expand Up @@ -32,7 +31,8 @@ function isValidActionsMapValue(actionsMapValue) {
}

function fromActionsMap(actionsMap) {
return reduce(actionsMap, (actionCreatorsMap, actionsMapValue, type) => {
return Object.keys(actionsMap).reduce((actionCreatorsMap, type) => {
const actionsMapValue = actionsMap[type];
invariant(
isValidActionsMapValue(actionsMapValue),
'Expected function, undefined, or array with payload and meta ' +
Expand All @@ -41,7 +41,6 @@ function fromActionsMap(actionsMap) {
const actionCreator = isArray(actionsMapValue)
? createAction(type, ...actionsMapValue)
: createAction(type, actionsMapValue);

return { ...actionCreatorsMap, [camelCase(type)]: actionCreator };
}, {});
}
Expand Down