From 01c8f123defdd18e79020f9b55e8b034e44f848f Mon Sep 17 00:00:00 2001 From: threehams Date: Tue, 19 Jul 2016 22:40:28 -0700 Subject: [PATCH] Use path imports for Lodash methods. --- src/extendReactClass.js | 7 ++++--- src/index.js | 6 +++--- src/isIterable.js | 9 +++++---- src/linkClass.js | 7 ++++--- src/makeConfiguration.js | 10 ++++++---- src/parseStyleName.js | 7 ++++--- src/wrapStatelessFunction.js | 9 +++++---- 7 files changed, 31 insertions(+), 24 deletions(-) diff --git a/src/extendReactClass.js b/src/extendReactClass.js index b5cfb2d..7a4c4fb 100644 --- a/src/extendReactClass.js +++ b/src/extendReactClass.js @@ -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'; @@ -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 }); diff --git a/src/index.js b/src/index.js index 7ee7e4e..a4b2071 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,4 @@ -import _ from 'lodash'; +import isFunction from 'lodash/isFunction'; import extendReactClass from './extendReactClass'; import wrapStatelessFunction from './wrapStatelessFunction'; import makeConfiguration from './makeConfiguration'; @@ -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); }; /** @@ -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]); diff --git a/src/isIterable.js b/src/isIterable.js index 2c800b1..54e97eb 100644 --- a/src/isIterable.js +++ b/src/isIterable.js @@ -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'; /** @@ -10,7 +11,7 @@ const OLD_ITERATOR_SYMBOL = '@@iterator'; export default (maybeIterable: any): boolean => { let iterator; - if (!_.isObject(maybeIterable)) { + if (!isObject(maybeIterable)) { return false; } @@ -20,5 +21,5 @@ export default (maybeIterable: any): boolean => { iterator = maybeIterable[OLD_ITERATOR_SYMBOL]; } - return _.isFunction(iterator); + return isFunction(iterator); }; diff --git a/src/linkClass.js b/src/linkClass.js index ea199e9..cfb785b 100644 --- a/src/linkClass.js +++ b/src/linkClass.js @@ -1,4 +1,5 @@ -import _ from 'lodash'; +import isArray from 'lodash/isArray'; +import isObject from 'lodash/isObject'; import React, { ReactElement } from 'react'; @@ -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); @@ -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; } diff --git a/src/makeConfiguration.js b/src/makeConfiguration.js index 83b2d41..c0e927d 100644 --- a/src/makeConfiguration.js +++ b/src/makeConfiguration.js @@ -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 @@ -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.'); } diff --git a/src/parseStyleName.js b/src/parseStyleName.js index 39c328a..b279192 100644 --- a/src/parseStyleName.js +++ b/src/parseStyleName.js @@ -1,4 +1,5 @@ -import _ from 'lodash'; +import trim from 'lodash/trim'; +import filter from 'lodash/filter'; const styleNameIndex = {}; @@ -8,8 +9,8 @@ export default (styleNamePropertyValue: string, allowMultiple: boolean): Array