Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Use path imports for Lodash methods.
  • Loading branch information
threehams committed Jul 20, 2016
commit 01c8f123defdd18e79020f9b55e8b034e44f848f
7 changes: 4 additions & 3 deletions src/extendReactClass.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable react/prop-types */

import React from 'react';
import _ from 'lodash';
import assign from 'lodash/assign';
import isObject from 'lodash/isObject';
import hoistNonReactStatics from 'hoist-non-react-statics';
import linkClass from './linkClass';

Expand All @@ -21,8 +22,8 @@ export default (Component: Object, defaultStyles: Object, options: Object) => {

if (this.props.styles) {
styles = this.props.styles;
} else if (_.isObject(defaultStyles)) {
this.props = _.assign({}, this.props, {
} else if (isObject(defaultStyles)) {
this.props = assign({}, this.props, {
styles: defaultStyles
});

Expand Down
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _ from 'lodash';
import isFunction from 'lodash/isFunction';
import extendReactClass from './extendReactClass';
import wrapStatelessFunction from './wrapStatelessFunction';
import makeConfiguration from './makeConfiguration';
Expand All @@ -12,7 +12,7 @@ type TypeOptions = {};
* Determines if the given object has the signature of a class that inherits React.Component.
*/
const isReactComponent = (maybeReactComponent: any): boolean => {
return 'prototype' in maybeReactComponent && _.isFunction(maybeReactComponent.prototype.render);
return 'prototype' in maybeReactComponent && isFunction(maybeReactComponent.prototype.render);
};

/**
Expand Down Expand Up @@ -48,7 +48,7 @@ const decoratorConstructor = (defaultStyles: Object, options: TypeOptions): Func
};

export default (...args) => {
if (_.isFunction(args[0])) {
if (isFunction(args[0])) {
return functionConstructor(args[0], args[1], args[2]);
} else {
return decoratorConstructor(args[0], args[1]);
Expand Down
9 changes: 5 additions & 4 deletions src/isIterable.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import _ from 'lodash';
import isFunction from 'lodash/isFunction';
import isObject from 'lodash/isObject';

const ITERATOR_SYMBOL = typeof Symbol !== 'undefined' && _.isFunction(Symbol) && Symbol.iterator;
const ITERATOR_SYMBOL = typeof Symbol !== 'undefined' && isFunction(Symbol) && Symbol.iterator;
const OLD_ITERATOR_SYMBOL = '@@iterator';

/**
Expand All @@ -10,7 +11,7 @@ const OLD_ITERATOR_SYMBOL = '@@iterator';
export default (maybeIterable: any): boolean => {
let iterator;

if (!_.isObject(maybeIterable)) {
if (!isObject(maybeIterable)) {
return false;
}

Expand All @@ -20,5 +21,5 @@ export default (maybeIterable: any): boolean => {
iterator = maybeIterable[OLD_ITERATOR_SYMBOL];
}

return _.isFunction(iterator);
return isFunction(iterator);
};
7 changes: 4 additions & 3 deletions src/linkClass.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import _ from 'lodash';
import isArray from 'lodash/isArray';
import isObject from 'lodash/isObject';
import React, {
ReactElement
} from 'react';
Expand Down Expand Up @@ -26,7 +27,7 @@ const linkElement = (element: ReactElement, styles: Object, configuration: Objec

if (React.isValidElement(elementShallowCopy.props.children)) {
elementShallowCopy.props.children = linkElement(React.Children.only(elementShallowCopy.props.children), styles, configuration);
} else if (_.isArray(elementShallowCopy.props.children) || isIterable(elementShallowCopy.props.children)) {
} else if (isArray(elementShallowCopy.props.children) || isIterable(elementShallowCopy.props.children)) {
elementShallowCopy.props.children = React.Children.map(elementShallowCopy.props.children, (node) => {
if (React.isValidElement(node)) {
return linkElement(node, styles, configuration);
Expand Down Expand Up @@ -65,7 +66,7 @@ const linkElement = (element: ReactElement, styles: Object, configuration: Objec
*/
export default (element: ReactElement, styles = {}, configuration = {}): ReactElement => {
// @see https://github.com/gajus/react-css-modules/pull/30
if (!_.isObject(element)) {
if (!isObject(element)) {
return element;
}

Expand Down
10 changes: 6 additions & 4 deletions src/makeConfiguration.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import _ from 'lodash';
import isUndefined from 'lodash/isUndefined';
import isBoolean from 'lodash/isBoolean';
import forEach from 'lodash/forEach';

/**
* @typedef CSSModules~Options
Expand All @@ -17,12 +19,12 @@ export default (userConfiguration = {}) => {
errorWhenNotFound: true
};

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

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

Expand Down
7 changes: 4 additions & 3 deletions src/parseStyleName.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import _ from 'lodash';
import trim from 'lodash/trim';
import filter from 'lodash/filter';

const styleNameIndex = {};

Expand All @@ -8,8 +9,8 @@ export default (styleNamePropertyValue: string, allowMultiple: boolean): Array<s
if (styleNameIndex[styleNamePropertyValue]) {
styleNames = styleNameIndex[styleNamePropertyValue];
} else {
styleNames = _.trim(styleNamePropertyValue).split(' ');
styleNames = _.filter(styleNames);
styleNames = trim(styleNamePropertyValue).split(' ');
styleNames = filter(styleNames);

styleNameIndex[styleNamePropertyValue] = styleNames;
}
Expand Down
9 changes: 5 additions & 4 deletions src/wrapStatelessFunction.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable react/prop-types */

import _ from 'lodash';
import isObject from 'lodash/isObject';
import assign from 'lodash/assign';
import React from 'react';
import linkClass from './linkClass';

Expand All @@ -15,8 +16,8 @@ export default (Component: Function, defaultStyles: Object, options: Object): Fu
if (props.styles) {
useProps = props;
styles = props.styles;
} else if (_.isObject(defaultStyles)) {
useProps = _.assign({}, props, {
} else if (isObject(defaultStyles)) {
useProps = assign({}, props, {
styles: defaultStyles
});

Expand All @@ -35,7 +36,7 @@ export default (Component: Function, defaultStyles: Object, options: Object): Fu
return React.createElement('noscript');
};

_.assign(WrappedComponent, Component);
assign(WrappedComponent, Component);

return WrappedComponent;
};