diff --git a/package.json b/package.json index 718e7e6a2a..8239d5b9cb 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,10 @@ }, "dependencies": { "invariant": "^2.0.0", - "warning": "^2.0.0" + "warning": "^2.0.0", + "lodash.isplainobject": "^3.2.0", + "lodash.mapvalues": "^3.0.1", + "lodash.pick": "^3.1.0" }, "npmName": "redux", "npmFileMap": [ diff --git a/src/createStore.js b/src/createStore.js index 296bf35caf..fb730c2db3 100644 --- a/src/createStore.js +++ b/src/createStore.js @@ -1,5 +1,5 @@ import invariant from 'invariant'; -import isPlainObject from './utils/isPlainObject'; +import isPlainObject from 'lodash.isplainobject'; /** * These are private action types reserved by Redux. diff --git a/src/utils/bindActionCreators.js b/src/utils/bindActionCreators.js index 499d91596b..65bc3798ae 100644 --- a/src/utils/bindActionCreators.js +++ b/src/utils/bindActionCreators.js @@ -1,5 +1,5 @@ import invariant from 'invariant'; -import mapValues from '../utils/mapValues'; +import mapValues from 'lodash.mapvalues'; function bindActionCreator(actionCreator, dispatch) { return (...args) => dispatch(actionCreator(...args)); diff --git a/src/utils/combineReducers.js b/src/utils/combineReducers.js index 8ba298991a..02291125ae 100644 --- a/src/utils/combineReducers.js +++ b/src/utils/combineReducers.js @@ -1,7 +1,7 @@ import { ActionTypes } from '../createStore'; -import isPlainObject from '../utils/isPlainObject'; -import mapValues from '../utils/mapValues'; -import pick from '../utils/pick'; +import isPlainObject from 'lodash.isplainobject'; +import mapValues from 'lodash.mapvalues'; +import pick from 'lodash.pick'; import invariant from 'invariant'; import warning from 'warning'; diff --git a/src/utils/isPlainObject.js b/src/utils/isPlainObject.js deleted file mode 100644 index db3f6a0113..0000000000 --- a/src/utils/isPlainObject.js +++ /dev/null @@ -1,23 +0,0 @@ -var fnToString = (fn) => Function.prototype.toString.call(fn); - -/** - * @param {any} obj The object to inspect. - * @returns {boolean} True if the argument appears to be a plain object. - */ -export default function isPlainObject(obj) { - if (!obj || typeof obj !== 'object') { - return false; - } - - var proto = typeof obj.constructor === 'function' ? Object.getPrototypeOf(obj) : Object.prototype; - - if (proto === null) { - return true; - } - - var constructor = proto.constructor; - - return typeof constructor === 'function' - && constructor instanceof constructor - && fnToString(constructor) === fnToString(Object); -} diff --git a/src/utils/mapValues.js b/src/utils/mapValues.js deleted file mode 100644 index bb87ac551d..0000000000 --- a/src/utils/mapValues.js +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Applies a function to every key-value pair inside an object. - * - * @param {Object} obj The source object. - * @param {Function} fn The mapper function taht receives the value and the key. - * @returns {Object} A new object that contains the mapped values for the keys. - */ -export default function mapValues(obj, fn) { - return Object.keys(obj).reduce((result, key) => { - result[key] = fn(obj[key], key); - return result; - }, {}); -} diff --git a/src/utils/pick.js b/src/utils/pick.js deleted file mode 100644 index 518c055e61..0000000000 --- a/src/utils/pick.js +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Picks key-value pairs from an object where values satisfy a predicate. - * - * @param {Object} obj The object to pick from. - * @param {Function} fn The predicate the values must satisfy to be copied. - * @returns {Object} The object with the values that satisfied the predicate. - */ -export default function pick(obj, fn) { - return Object.keys(obj).reduce((result, key) => { - if (fn(obj[key])) { - result[key] = obj[key]; - } - return result; - }, {}); -} diff --git a/test/utils/isPlainObject.spec.js b/test/utils/isPlainObject.spec.js deleted file mode 100644 index 963c7f610c..0000000000 --- a/test/utils/isPlainObject.spec.js +++ /dev/null @@ -1,24 +0,0 @@ -import expect from 'expect'; -import isPlainObject from '../../src/utils/isPlainObject'; -import contextify from 'contextify'; - -describe('isPlainObject', () => { - it('should return true only if plain object', () => { - function Test() { - this.prop = 1; - } - - const sandbox = contextify(); - sandbox.run('var fromAnotherRealm = {};'); - - expect(isPlainObject(sandbox.fromAnotherRealm)).toBe(true); - expect(isPlainObject(new Test())).toBe(false); - expect(isPlainObject(new Date())).toBe(false); - expect(isPlainObject([1, 2, 3])).toBe(false); - expect(isPlainObject(null)).toBe(false); - expect(isPlainObject()).toBe(false); - expect(isPlainObject({ 'x': 1, 'y': 2 })).toBe(true); - - sandbox.dispose(); - }); -}); diff --git a/test/utils/mapValues.spec.js b/test/utils/mapValues.spec.js deleted file mode 100644 index 007848af81..0000000000 --- a/test/utils/mapValues.spec.js +++ /dev/null @@ -1,16 +0,0 @@ -import expect from 'expect'; -import mapValues from '../../src/utils/mapValues'; - -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' - }); - }); -}); - diff --git a/test/utils/pick.spec.js b/test/utils/pick.spec.js deleted file mode 100644 index 14e02d5db0..0000000000 --- a/test/utils/pick.spec.js +++ /dev/null @@ -1,16 +0,0 @@ -import expect from 'expect'; -import pick from '../../src/utils/pick'; - -describe('pick', () => { - it('should return object with picked values', () => { - const test = { - name: 'lily', - age: 20 - }; - expect( - pick(test, x => typeof x === 'string') - ).toEqual({ - name: 'lily' - }); - }); -});