Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import lodash functions instead of whole lib #857

Merged
merged 2 commits into from
Jul 9, 2019
Merged
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
17 changes: 16 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,22 @@
},
"dependencies": {
"immutable": "^3.8.2",
"lodash": "^4.17.11",
"lodash.assignin": "^4.2.0",
"lodash.compact": "^3.0.1",
"lodash.flatten": "^4.4.0",
"lodash.flattendeep": "^4.4.0",
"lodash.flow": "^3.5.0",
"lodash.flowright": "^3.5.0",
"lodash.forin": "^4.4.0",
"lodash.isequal": "^4.5.0",
"lodash.isfinite": "^3.3.2",
"lodash.isstring": "^4.0.1",
"lodash.merge": "^4.6.1",
"lodash.pick": "^4.4.0",
"lodash.pickby": "^4.6.0",
"lodash.range": "^3.2.0",
"lodash.union": "^4.6.0",
"lodash.uniq": "^4.5.0",
"max-safe-integer": "^2.0.0",
"prop-types": "^15.7.2",
"react-redux": "^5.1.1",
Expand Down
4 changes: 2 additions & 2 deletions src/components/PageDropdown.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import _ from 'lodash';
import isFinite from 'lodash.isfinite';

/** Gets a range from a single value.
* TODO: Could probably make this take a predicate to avoid running through the loop twice */
const getRange = (number) => {
if (!_.isFinite(number)) { return [0] }
if (!isFinite(number)) { return [0] }

return Array(number).fill().map((_, i) => i + 1);
}
Expand Down
7 changes: 4 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
import { createProvider } from 'react-redux';
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import _ from 'lodash';
import forIn from 'lodash.forin';
import pickBy from 'lodash.pickby';

import corePlugin from './core';
import init from './utils/initializer';
Expand Down Expand Up @@ -45,7 +46,7 @@ class Griddle extends Component {
this.provider = createProvider(storeKey);

this.storeListener = new StoreListener(this.store);
_.forIn(this.listeners, (listener, name) => {
forIn(this.listeners, (listener, name) => {
this.storeListener.addListener(listener, name, {
events: this.events,
selectors: this.selectors
Expand All @@ -54,7 +55,7 @@ class Griddle extends Component {
}

componentWillReceiveProps(nextProps) {
const newState = _.pickBy(nextProps, (value, key) => {
const newState = pickBy(nextProps, (value, key) => {
return this.props[key] !== value;
});

Expand Down
4 changes: 2 additions & 2 deletions src/plugins/local/selectors/localSelectors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Immutable from 'immutable';
import { createSelector } from 'reselect';
import _ from 'lodash';
import isFinite from 'lodash.isfinite';

import { defaultSort } from '../../../utils/sortUtils';
import { getVisibleDataForColumns } from '../../../utils/dataUtils';
Expand Down Expand Up @@ -125,7 +125,7 @@ export const maxPageSelector = createSelector(

const result = calc > Math.floor(calc) ? Math.floor(calc) + 1 : Math.floor(calc);

return _.isFinite(result) ? result : 1;
return isFinite(result) ? result : 1;
}
)

Expand Down
10 changes: 6 additions & 4 deletions src/selectors/dataSelectors.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import Immutable from 'immutable';
import { createSelector, createSelectorCreator, defaultMemoize } from 'reselect';
import _ from 'lodash';
import isEqual from 'lodash.isequal';
import isFinite from 'lodash.isfinite';
import union from 'lodash.union';

const createDeepEqualSelector = createSelectorCreator(
defaultMemoize,
_.isEqual,
isEqual,
)

import MAX_SAFE_INTEGER from 'max-safe-integer'
Expand Down Expand Up @@ -43,7 +45,7 @@ export const maxPageSelector = createSelector(

const result = calc > Math.floor(calc) ? Math.floor(calc) + 1 : Math.floor(calc);

return _.isFinite(result) ? result : 1;
return isFinite(result) ? result : 1;
}
);

Expand Down Expand Up @@ -76,7 +78,7 @@ export const allColumnsSelector = createSelector(
Object.keys(renderProperties.get('columnProperties').toJSON()) :
[];

return _.union(dataColumns, columnPropertyColumns);
return union(dataColumns, columnPropertyColumns);
}
);

Expand Down
4 changes: 2 additions & 2 deletions src/utils/__tests__/initilizerTests.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'ava';
import _ from 'lodash';
import range from 'lodash.range';

import init from '../initializer';

Expand Down Expand Up @@ -260,7 +260,7 @@ test('init returns composed reducer given plugins', (assert) => {
});

test('init returns flattened/compacted reduxMiddleware given plugins', (assert) => {
const mw = _.range(0, 4).map(i => () => i);
const mw = range(0, 4).map(i => () => i);
const ctx = {
props: {
plugins: [
Expand Down
33 changes: 20 additions & 13 deletions src/utils/compositionUtils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import _ from 'lodash';
import pickBy from 'lodash.pickby';
import assignIn from 'lodash.assignin';
import pick from 'lodash.pick';
import flattenDeep from 'lodash.flattendeep';
import uniq from 'lodash.uniq';
import flow from 'lodash.flow';
import flowRight from 'lodash.flowright';
import isString from 'lodash.isstring';

/** Extends an array rather than known list of objects */
//TODO: Look at using object.assign
Expand All @@ -10,7 +17,7 @@ export function extendArray(objects) {
objects.unshift({});

//Buid the combined object
let combinedObject = _.extend.apply(this, objects);
let combinedObject = assignIn.apply(this, objects);
StevenTCramer marked this conversation as resolved.
Show resolved Hide resolved

//TODO: why are we doing this? is it necessary
objects.shift();
Expand Down Expand Up @@ -54,7 +61,7 @@ export function getPropertiesByEnding(ending, object) {
export function getObjectWherePropertyEndsWith(ending, object) {
const keys = getPropertiesByEnding(ending, object);

return _.pick(object, keys);
return pick(object, keys);
}

/** Creates a new reducer by taking the output of the first reducer as state to the second
Expand Down Expand Up @@ -84,7 +91,7 @@ export function composeReducers(reducers) {
* @param {Object <array>} objects - An array of objects
*/
export function getKeysForObjects(objects) {
return _.uniq(_.flattenDeep(objects.map(o => Object.keys(o))));
return uniq(flattenDeep(objects.map(o => Object.keys(o))));
}

/** Determines if a given key is a Griddle hook reducer
Expand All @@ -99,7 +106,7 @@ export function isKeyGriddleHook(key) {
* @param {Object} reducerObject - The reducer object to remove hooks from
*/
export function removeHooksFromObject(reducerObject) {
return _.pickBy(reducerObject, (value, key) => {
return pickBy(reducerObject, (value, key) => {
if (isKeyGriddleHook(key)) {
return false;
}
Expand All @@ -124,14 +131,14 @@ export function removeKeyNamePartFromObject(reducerObject, keyString) {
*/
export function getBeforeHooksFromObject(reducerObject) {
return removeKeyNamePartFromObject(
_.pickBy(reducerObject, (value, key) => key.endsWith('BEFORE')), '_BEFORE');
pickBy(reducerObject, (value, key) => key.endsWith('BEFORE')), '_BEFORE');
}

/** Gets an object that consists of only the BEFORE_REDUCE hooks.
* @param {Object} reducerObject - the reducer to get the BEFORE_REDUCE hooks from
*/
export function getBeforeReduceHooksFromObject(reducerObject) {
return _.pickBy(reducerObject, (value, key) => key === 'BEFORE_REDUCE')
return pickBy(reducerObject, (value, key) => key === 'BEFORE_REDUCE')
}


Expand All @@ -140,14 +147,14 @@ export function getBeforeReduceHooksFromObject(reducerObject) {
*/
export function getAfterHooksFromObject(reducerObject) {
return removeKeyNamePartFromObject(
_.pickBy(reducerObject, (value, key) => key.endsWith('AFTER')), '_AFTER');
pickBy(reducerObject, (value, key) => key.endsWith('AFTER')), '_AFTER');
}

/** Gets an object that conists of only the AFTER_REDUCE hooks.
* @param {Object} reducerObject - the reducer to get the AFTER_REDUCE hooks from
*/
export function getAfterReduceHooksFromObject(reducerObject) {
return _.pickBy(reducerObject, (value, key) => key === 'AFTER_REDUCE');
return pickBy(reducerObject, (value, key) => key === 'AFTER_REDUCE');
}

/** Combines the given reducer objects left to right
Expand Down Expand Up @@ -186,7 +193,7 @@ function buildGriddleReducerObject(reducerObjects) {
if (reducerObjects.length > 0) {
// remove the hooks and extend the object
for(const key in reducerObjects) {
const reducer = reducerObjects[key];
const reducer = pickBy(reducerObjects[key], (value, key) => isString(key));
StevenTCramer marked this conversation as resolved.
Show resolved Hide resolved
reducerMethodsWithoutHooks.push(removeHooksFromObject(reducer));
beforeHooks.push(getBeforeHooksFromObject(reducer));
afterHooks.push(getAfterHooksFromObject(reducer));
Expand Down Expand Up @@ -232,7 +239,7 @@ export function callReducerWithBeforeAfterPipe(reducerObject, state, action) {

const partialCall = (partialAction => partialState => call(partialState, partialAction))(action);

const method = _.flow([before, partialCall, after]);
const method = flow([before, partialCall, after]);

return method(state);
}
Expand Down Expand Up @@ -295,13 +302,13 @@ export function wrapMethodsByWordEnding(componentArray, wordEnding, keyReplaceSt
// Determine if we are working with an HoC that wraps another HoC
newObject[keyWithoutEnhancer] = keyWithoutEnhancer.endsWith('Container') || keyWithoutEnhancer.endsWith('Enhancer') ?
// If we are enhancing a container or enhancer flow this stuff since it's likely an HoC
_.flowRight(current[key], (current[keyWithoutEnhancer] || previous[keyWithoutEnhancer])) :
flowRight(current[key], (current[keyWithoutEnhancer] || previous[keyWithoutEnhancer])) :
// Wrap the current component in the Enhancer or container
current[key](current[keyWithoutEnhancer] || previous[keyWithoutEnhancer])
}
}

return _.pickBy(Object.assign(previous, current, newObject), (v, k) => (!k.endsWith(wordEnding))) ;
return pickBy(Object.assign(previous, current, newObject), (v, k) => (!k.endsWith(wordEnding))) ;
}, {})
}

Expand Down
8 changes: 4 additions & 4 deletions src/utils/initializer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import merge from 'lodash/merge';
import pickBy from 'lodash/pickBy';
import compact from 'lodash/compact';
import flatten from 'lodash/flatten';
import merge from 'lodash.merge';
import pickBy from 'lodash.pickby';
import compact from 'lodash.compact';
import flatten from 'lodash.flatten';
import {
buildGriddleReducer,
buildGriddleComponents
Expand Down
1 change: 0 additions & 1 deletion stories/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import withState from 'recompose/withState';
import { Provider, connect as reduxConnect } from 'react-redux';
import { createStore } from 'redux';
import { createSelector } from 'reselect';
import _ from 'lodash';

import GenericGriddle, {
connect,
Expand Down