Skip to content

Commit dd71bdb

Browse files
committed
Merge pull request reduxjs#129 from frankychung/replace-lodash-mapvalues
Replace lodash's mapValues
2 parents dbe1a17 + a6efb92 commit dd71bdb

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

src/utils/bindActionCreators.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import mapValues from 'lodash/object/mapValues';
1+
import mapValues from '../utils/mapValues';
22

33
export default function bindActionCreators(actionCreators, dispatch) {
44
return mapValues(actionCreators, actionCreator =>

src/utils/composeStores.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import mapValues from 'lodash/object/mapValues';
1+
import mapValues from '../utils/mapValues';
22
import pick from 'lodash/object/pick';
33

44
export default function composeStores(stores) {

src/utils/mapValues.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default function mapValues(obj, fn) {
2+
return Object.keys(obj).reduce((result, key) => {
3+
result[key] = fn(obj[key], key);
4+
return result;
5+
}, {});
6+
}

test/utils/mapValues.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import expect from 'expect';
2+
import mapValues from '../../src/utils/mapValues';
3+
4+
describe('Utils', () => {
5+
describe('mapValues', () => {
6+
it('should return object with mapped values', () => {
7+
const test = { 'a': 'c', 'b': 'd' };
8+
expect(mapValues(test, (val, key) => val + key)).toEqual({ 'a': 'ca', 'b': 'db' });
9+
});
10+
});
11+
});
12+

0 commit comments

Comments
 (0)