Skip to content
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

Replace lodash's mapValues #129

Merged
merged 3 commits into from
Jun 17, 2015
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
2 changes: 1 addition & 1 deletion src/utils/bindActionCreators.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import mapValues from 'lodash/object/mapValues';
import mapValues from '../utils/mapValues';

export default function bindActionCreators(actionCreators, dispatch) {
return mapValues(actionCreators, actionCreator =>
Expand Down
2 changes: 1 addition & 1 deletion src/utils/composeStores.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import mapValues from 'lodash/object/mapValues';
import mapValues from '../utils/mapValues';
import pick from 'lodash/object/pick';

export default function composeStores(stores) {
Expand Down
6 changes: 6 additions & 0 deletions src/utils/mapValues.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default function mapValues(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
result[key] = fn(obj[key], key);
return result;
}, {});
}
12 changes: 12 additions & 0 deletions test/utils/mapValues.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import expect from 'expect';
import mapValues from '../../src/utils/mapValues';

describe('Utils', () => {
describe('mapValues', () => {
it('should return object with mapped values', () => {
const test = { 'a': 'c', 'b': 'd' };
expect(mapValues(test, (val, key) => val + key)).toEqual({ 'a': 'ca', 'b': 'db' });
});
});
});