Skip to content

Commit e27a932

Browse files
committed
import lodash in a way that supports tree shaking
1 parent 0a622ea commit e27a932

File tree

7 files changed

+24
-24
lines changed

7 files changed

+24
-24
lines changed

src/extendReactClass.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import linkClass from './linkClass';
44
import React from 'react';
5-
import _ from 'lodash';
5+
import { isObject, assign } from 'lodash';
66
import hoistNonReactStatics from 'hoist-non-react-statics';
77

88
/**
@@ -21,8 +21,8 @@ export default (Component, defaultStyles, options) => {
2121

2222
if (this.props.styles) {
2323
styles = this.props.styles;
24-
} else if (_.isObject(defaultStyles)) {
25-
this.props = _.assign({}, this.props, {
24+
} else if (isObject(defaultStyles)) {
25+
this.props = assign({}, this.props, {
2626
styles: defaultStyles
2727
});
2828

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import _ from 'lodash';
1+
import { isFunction } from 'lodash';
22
import extendReactClass from './extendReactClass';
33
import wrapStatelessFunction from './wrapStatelessFunction';
44

@@ -13,7 +13,7 @@ let decoratorConstructor,
1313
* @returns {boolean}
1414
*/
1515
isReactComponent = (maybeReactComponent) => {
16-
return 'prototype' in maybeReactComponent && _.isFunction(maybeReactComponent.prototype.render);
16+
return 'prototype' in maybeReactComponent && isFunction(maybeReactComponent.prototype.render);
1717
};
1818

1919
/**
@@ -56,7 +56,7 @@ decoratorConstructor = (defaultStyles, options) => {
5656
};
5757

5858
export default (...args) => {
59-
if (_.isFunction(args[0])) {
59+
if (isFunction(args[0])) {
6060
return functionConstructor(args[0], args[1], args[2]);
6161
} else {
6262
return decoratorConstructor(args[0], args[1]);

src/isIterable.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import _ from 'lodash';
1+
import { isFunction, isObject } from 'lodash';
22

33
let ITERATOR_SYMBOL,
44
OLD_ITERATOR_SYMBOL;
55

6-
ITERATOR_SYMBOL = _.isFunction(Symbol) && Symbol.iterator;
6+
ITERATOR_SYMBOL = isFunction(Symbol) && Symbol.iterator;
77
OLD_ITERATOR_SYMBOL = '@@iterator';
88

99
/**
@@ -15,7 +15,7 @@ OLD_ITERATOR_SYMBOL = '@@iterator';
1515
export default (target) => {
1616
let iterator;
1717

18-
if (!_.isObject(target)) {
18+
if (!isObject(target)) {
1919
return false;
2020
}
2121

@@ -25,5 +25,5 @@ export default (target) => {
2525
iterator = target[OLD_ITERATOR_SYMBOL];
2626
}
2727

28-
return _.isFunction(iterator);
28+
return isFunction(iterator);
2929
};

src/linkClass.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import _ from 'lodash';
1+
import { isArray, isObject } from 'lodash';
22
import React from 'react';
33
import makeConfiguration from './makeConfiguration';
44
import isIterable from './isIterable';
@@ -28,7 +28,7 @@ linkElement = (element, styles, configuration) => {
2828

2929
if (React.isValidElement(elementShallowCopy.props.children)) {
3030
elementShallowCopy.props.children = linkElement(React.Children.only(elementShallowCopy.props.children), styles, configuration);
31-
} else if (_.isArray(elementShallowCopy.props.children) || isIterable(elementShallowCopy.props.children)) {
31+
} else if (isArray(elementShallowCopy.props.children) || isIterable(elementShallowCopy.props.children)) {
3232
elementShallowCopy.props.children = React.Children.map(elementShallowCopy.props.children, (node) => {
3333
if (React.isValidElement(node)) {
3434
return linkElement(node, styles, configuration);
@@ -69,7 +69,7 @@ export default (element, styles = {}, userConfiguration) => {
6969
let configuration;
7070

7171
// @see https://github.com/gajus/react-css-modules/pull/30
72-
if (!_.isObject(element)) {
72+
if (!isObject(element)) {
7373
return element;
7474
}
7575

src/makeConfiguration.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import _ from 'lodash';
1+
import { forEach, isUndefined, isBoolean } from 'lodash';
22
import Map from 'es6-map';
33

44
let userConfigurationIndex;
@@ -30,12 +30,12 @@ export default (userConfiguration = {}) => {
3030
errorWhenNotFound: true
3131
};
3232

33-
_.forEach(userConfiguration, (value, name) => {
34-
if (_.isUndefined(configuration[name])) {
33+
forEach(userConfiguration, (value, name) => {
34+
if (isUndefined(configuration[name])) {
3535
throw new Error('Unknown configuration property "' + name + '".');
3636
}
3737

38-
if (!_.isBoolean(value)) {
38+
if (!isBoolean(value)) {
3939
throw new Error('"' + name + '" property value must be a boolean.');
4040
}
4141

src/parseStyleName.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import _ from 'lodash';
1+
import { trim, filter } from 'lodash';
22

33
let styleNameIndex;
44

@@ -10,8 +10,8 @@ export default (styleNamePropertyValue: string, allowMultiple: boolean): Array<s
1010
if (styleNameIndex[styleNamePropertyValue]) {
1111
styleNames = styleNameIndex[styleNamePropertyValue];
1212
} else {
13-
styleNames = _.trim(styleNamePropertyValue).split(' ');
14-
styleNames = _.filter(styleNames);
13+
styleNames = trim(styleNamePropertyValue).split(' ');
14+
styleNames = filter(styleNames);
1515

1616
styleNameIndex[styleNamePropertyValue] = styleNames;
1717
}

src/wrapStatelessFunction.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable react/prop-types */
22

3-
import _ from 'lodash';
3+
import { isObject, assign } from 'lodash';
44
import React from 'react';
55
import linkClass from './linkClass';
66

@@ -22,8 +22,8 @@ export default (Component, defaultStyles, options) => {
2222
if (props.styles) {
2323
useProps = props;
2424
styles = props.styles;
25-
} else if (_.isObject(defaultStyles)) {
26-
useProps = _.assign({}, props, {
25+
} else if (isObject(defaultStyles)) {
26+
useProps = assign({}, props, {
2727
styles: defaultStyles
2828
});
2929

@@ -42,7 +42,7 @@ export default (Component, defaultStyles, options) => {
4242
return React.createElement('noscript');
4343
};
4444

45-
_.assign(WrappedComponent, Component);
45+
assign(WrappedComponent, Component);
4646

4747
return WrappedComponent;
4848
};

0 commit comments

Comments
 (0)