Skip to content

Commit 94b6a48

Browse files
committed
Merge pull request #131 from frankychung/replace-lodash-utils
Replace lodash utils
2 parents d925a04 + 974b7b8 commit 94b6a48

9 files changed

+59
-5
lines changed

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@
5555
"dependencies": {
5656
"babel-runtime": "^5.5.8",
5757
"envify": "^3.4.0",
58-
"invariant": "^2.0.0",
59-
"lodash": "^3.9.3"
58+
"invariant": "^2.0.0"
6059
},
6160
"browserify": {
6261
"transform": [

src/components/createConnector.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import identity from 'lodash/utility/identity';
1+
import identity from '../utils/identity';
22
import shallowEqual from '../utils/shallowEqual';
3-
import isPlainObject from 'lodash/lang/isPlainObject';
3+
import isPlainObject from '../utils/isPlainObject';
44
import invariant from 'invariant';
55

66
export default function createConnector(React) {

src/utils/composeStores.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import mapValues from '../utils/mapValues';
2-
import pick from 'lodash/object/pick';
2+
import pick from '../utils/pick';
33

44
export default function composeStores(stores) {
55
stores = pick(stores, (val) => typeof val === 'function');

src/utils/identity.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function identity(value) {
2+
return value;
3+
}

src/utils/isPlainObject.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function isPlainObject(obj) {
2+
return obj ? typeof obj === 'object' && Object.getPrototypeOf(obj) === Object.prototype : false;
3+
}

src/utils/pick.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default function pick(obj, fn) {
2+
return Object.keys(obj).reduce((result, key) => {
3+
if (fn(obj[key])) {
4+
result[key] = obj[key];
5+
}
6+
return result;
7+
}, {});
8+
}

test/utils/identity.spec.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import expect from 'expect';
2+
import identity from '../../src/utils/identity';
3+
4+
describe('Utils', () => {
5+
describe('identity', () => {
6+
it('should return first argument passed to it', () => {
7+
var test = { 'a': 1 };
8+
expect(identity(test, 'test')).toBe(test);
9+
});
10+
});
11+
});

test/utils/isPlainObject.spec.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import expect from 'expect';
2+
import isPlainObject from '../../src/utils/isPlainObject';
3+
4+
describe('Utils', () => {
5+
describe('isPlainObject', () => {
6+
it('should return true only if plain object', () => {
7+
function Test() {
8+
this.prop = 1;
9+
}
10+
11+
expect(isPlainObject(new Test())).toBe(false);
12+
expect(isPlainObject(new Date())).toBe(false);
13+
expect(isPlainObject([1, 2, 3])).toBe(false);
14+
expect(isPlainObject(null)).toBe(false);
15+
expect(isPlainObject()).toBe(false);
16+
expect(isPlainObject({ 'x': 1, 'y': 2 })).toBe(true);
17+
});
18+
});
19+
});

test/utils/pick.spec.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import expect from 'expect';
2+
import pick from '../../src/utils/pick';
3+
4+
describe('Utils', () => {
5+
describe('pick', () => {
6+
it('should return object with picked values', () => {
7+
const test = { 'name': 'lily', 'age': 20 };
8+
expect(pick(test, x => typeof x === 'string')).toEqual({ 'name': 'lily' });
9+
});
10+
});
11+
});

0 commit comments

Comments
 (0)