diff --git a/package.json b/package.json index 4a65d918b8..12dd3c8333 100644 --- a/package.json +++ b/package.json @@ -55,8 +55,7 @@ "dependencies": { "babel-runtime": "^5.5.8", "envify": "^3.4.0", - "invariant": "^2.0.0", - "lodash": "^3.9.3" + "invariant": "^2.0.0" }, "browserify": { "transform": [ diff --git a/src/components/createConnector.js b/src/components/createConnector.js index 1a826c1e0d..3dcf48339e 100644 --- a/src/components/createConnector.js +++ b/src/components/createConnector.js @@ -1,6 +1,6 @@ -import identity from 'lodash/utility/identity'; +import identity from '../utils/identity'; import shallowEqual from '../utils/shallowEqual'; -import isPlainObject from 'lodash/lang/isPlainObject'; +import isPlainObject from '../utils/isPlainObject'; import invariant from 'invariant'; export default function createConnector(React) { diff --git a/src/utils/composeStores.js b/src/utils/composeStores.js index 4122006ce4..21ec65c693 100644 --- a/src/utils/composeStores.js +++ b/src/utils/composeStores.js @@ -1,5 +1,5 @@ import mapValues from '../utils/mapValues'; -import pick from 'lodash/object/pick'; +import pick from '../utils/pick'; export default function composeStores(stores) { stores = pick(stores, (val) => typeof val === 'function'); diff --git a/src/utils/identity.js b/src/utils/identity.js new file mode 100644 index 0000000000..8c690a8859 --- /dev/null +++ b/src/utils/identity.js @@ -0,0 +1,3 @@ +export default function identity(value) { + return value; +} diff --git a/src/utils/isPlainObject.js b/src/utils/isPlainObject.js new file mode 100644 index 0000000000..a5845486cf --- /dev/null +++ b/src/utils/isPlainObject.js @@ -0,0 +1,3 @@ +export default function isPlainObject(obj) { + return obj ? typeof obj === 'object' && Object.getPrototypeOf(obj) === Object.prototype : false; +} diff --git a/src/utils/pick.js b/src/utils/pick.js new file mode 100644 index 0000000000..2c9719c1c0 --- /dev/null +++ b/src/utils/pick.js @@ -0,0 +1,8 @@ +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/identity.spec.js b/test/utils/identity.spec.js new file mode 100644 index 0000000000..4b45007c74 --- /dev/null +++ b/test/utils/identity.spec.js @@ -0,0 +1,11 @@ +import expect from 'expect'; +import identity from '../../src/utils/identity'; + +describe('Utils', () => { + describe('identity', () => { + it('should return first argument passed to it', () => { + var test = { 'a': 1 }; + expect(identity(test, 'test')).toBe(test); + }); + }); +}); diff --git a/test/utils/isPlainObject.spec.js b/test/utils/isPlainObject.spec.js new file mode 100644 index 0000000000..13cd49a1cf --- /dev/null +++ b/test/utils/isPlainObject.spec.js @@ -0,0 +1,19 @@ +import expect from 'expect'; +import isPlainObject from '../../src/utils/isPlainObject'; + +describe('Utils', () => { + describe('isPlainObject', () => { + it('should return true only if plain object', () => { + function Test() { + this.prop = 1; + } + + 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); + }); + }); +}); diff --git a/test/utils/pick.spec.js b/test/utils/pick.spec.js new file mode 100644 index 0000000000..6cd95f7395 --- /dev/null +++ b/test/utils/pick.spec.js @@ -0,0 +1,11 @@ +import expect from 'expect'; +import pick from '../../src/utils/pick'; + +describe('Utils', () => { + 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' }); + }); + }); +});