Skip to content

Commit

Permalink
fix(lodash): use lodash v4, reduce build size
Browse files Browse the repository at this point in the history
helper now uses lodash v4, let's use lodash v4 in IS too
  • Loading branch information
vvo committed Aug 24, 2016
1 parent 71010c1 commit 216d1e0
Show file tree
Hide file tree
Showing 33 changed files with 80 additions and 81 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"classnames": "^2.2.5",
"events": "^1.1.0",
"hogan.js": "^3.0.2",
"lodash": "^3.10.1",
"lodash": "^4.15.0",
"react": "^15.3.1",
"react-dom": "^15.3.1",
"react-nouislider": "^1.13.0",
Expand Down
2 changes: 1 addition & 1 deletion scripts/dev-functional-tests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-console, no-magic-numbers */

import debounce from 'lodash/function/debounce';
import debounce from 'lodash/debounce';
import watch from './dev-functional-tests-compile-watch.js';

import {spawn} from 'child_process';
Expand Down
8 changes: 4 additions & 4 deletions src/components/CurrentRefinedValues/CurrentRefinedValues.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import React from 'react';
import Template from '../Template.js';

import {isSpecialClick} from '../../lib/utils.js';
import map from 'lodash/collection/map';
import cloneDeep from 'lodash/lang/cloneDeep';
import isEqual from 'lodash/lang/isEqual';
import map from 'lodash/map';
import cloneDeep from 'lodash/cloneDeep';
import isEqual from 'lodash/isEqual';

class CurrentRefinedValues extends React.Component {
shouldComponentUpdate(nextProps) {
Expand Down Expand Up @@ -56,7 +56,7 @@ class CurrentRefinedValues extends React.Component {
<div>
{this._clearAllElement('before', this.props.clearAllPosition)}
<div className={this.props.cssClasses.list}>
{map(this.props.refinements, this._refinementElement, this)}
{map(this.props.refinements, this._refinementElement.bind(this))}
</div>
{this._clearAllElement('after', this.props.clearAllPosition)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import React from 'react';
import expect from 'expect';
import TestUtils from 'react-addons-test-utils';

import forEach from 'lodash/collection/forEach';
import map from 'lodash/collection/map';
import forEach from 'lodash/forEach';
import map from 'lodash/map';

import CurrentRefinedValues from '../CurrentRefinedValues.js';
import Template from '../../Template';
Expand Down
4 changes: 2 additions & 2 deletions src/components/Hits.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import map from 'lodash/collection/map';
import map from 'lodash/map';
import Template from './Template.js';
import hasKey from 'lodash/object/has';
import hasKey from 'lodash/has';
import cx from 'classnames';

class Hits extends React.Component {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Pagination/Pagination.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import forEach from 'lodash/collection/forEach';
import defaultsDeep from 'lodash/object/defaultsDeep';
import forEach from 'lodash/forEach';
import defaultsDeep from 'lodash/defaultsDeep';
import {isSpecialClick} from '../../lib/utils.js';

import Paginator from './Paginator.js';
Expand Down
2 changes: 1 addition & 1 deletion src/components/Pagination/PaginationLink.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import isEqual from 'lodash/lang/isEqual';
import isEqual from 'lodash/isEqual';

class PaginationLink extends React.Component {
componentWillMount() {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Pagination/Paginator.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import range from 'lodash/utility/range';
import range from 'lodash/range';

class Paginator {
constructor(params) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/PriceRanges/PriceRanges.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import Template from '../Template.js';
import PriceRangesForm from './PriceRangesForm.js';
import cx from 'classnames';
import isEqual from 'lodash/lang/isEqual';
import isEqual from 'lodash/isEqual';

class PriceRanges extends React.Component {
componentWillMount() {
Expand Down
2 changes: 1 addition & 1 deletion src/components/RefinementList/RefinementList.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {isSpecialClick} from '../../lib/utils.js';

import Template from '../Template.js';
import RefinementListItem from './RefinementListItem.js';
import isEqual from 'lodash/lang/isEqual';
import isEqual from 'lodash/isEqual';

class RefinementList extends React.Component {
constructor(props) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/RefinementList/RefinementListItem.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';

import Template from '../Template.js';
import isEqual from 'lodash/lang/isEqual';
import isEqual from 'lodash/isEqual';

class RefinementListItem extends React.Component {
componentWillMount() {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Slider/Slider.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react';
import omit from 'lodash/object/omit';
import omit from 'lodash/omit';

import Nouislider from 'react-nouislider';

let cssPrefix = 'ais-range-slider--';

import isEqual from 'lodash/lang/isEqual';
import isEqual from 'lodash/isEqual';

class Slider extends React.Component {
componentWillMount() {
Expand Down
8 changes: 4 additions & 4 deletions src/components/Template.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react';

import curry from 'lodash/function/curry';
import cloneDeep from 'lodash/lang/cloneDeep';
import mapValues from 'lodash/object/mapValues';
import curry from 'lodash/curry';
import cloneDeep from 'lodash/cloneDeep';
import mapValues from 'lodash/mapValues';

import hogan from 'hogan.js';

import isEqual from 'lodash/lang/isEqual';
import isEqual from 'lodash/isEqual';

class Template extends React.Component {
shouldComponentUpdate(nextProps) {
Expand Down
2 changes: 1 addition & 1 deletion src/decorators/headerFooter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import React from 'react';

import cx from 'classnames';
import getKey from 'lodash/object/get';
import getKey from 'lodash/get';

import Template from '../components/Template.js';

Expand Down
27 changes: 13 additions & 14 deletions src/lib/InstantSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// https://github.com/algolia/instantsearch.js/issues/1024#issuecomment-221618284
import algoliasearch from 'algoliasearch/src/browser/builds/algoliasearchLite.js';
import algoliasearchHelper from 'algoliasearch-helper';
import forEach from 'lodash/collection/forEach';
import merge from 'lodash/object/merge';
import union from 'lodash/array/union';
import clone from 'lodash/lang/clone';
import isObject from 'lodash/lang/isObject';
import forEach from 'lodash/forEach';
import mergeWith from 'lodash/mergeWith';
import union from 'lodash/union';
import clone from 'lodash/clone';
import isObject from 'lodash/isObject';
import {EventEmitter} from 'events';
import urlSyncWidget from './url-sync.js';
import version from './version.js';
Expand Down Expand Up @@ -164,7 +164,7 @@ Usage: instantsearch({
}

_render(helper, results, state) {
forEach(this.widgets, function(widget) {
forEach(this.widgets, widget => {
if (!widget.render) {
return;
}
Expand All @@ -175,23 +175,22 @@ Usage: instantsearch({
helper,
createURL: this._createAbsoluteURL
});
}, this);
});
this.emit('render');
}

_init(state, helper) {
const {_onHistoryChange, templatesConfig} = this;
forEach(this.widgets, function(widget) {
forEach(this.widgets, widget => {
if (widget.init) {
widget.init({
state,
helper,
templatesConfig,
templatesConfig: this.templatesConfig,
createURL: this._createAbsoluteURL,
onHistoryChange: _onHistoryChange
onHistoryChange: this._onHistoryChange
});
}
}, this);
});
}
}

Expand All @@ -210,13 +209,13 @@ function enhanceConfiguration(searchParametersFromUrl) {

// avoid mutating objects
if (isObject(a)) {
return merge({}, a, b, customizer);
return mergeWith({}, a, b, customizer);
}

return undefined;
};

return merge(
return mergeWith(
{},
configuration,
partialConfiguration,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/__tests__/InstantSearch-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import EventEmitter from 'events';

import expect from 'expect';
import range from 'lodash/utility/range';
import range from 'lodash/range';
import sinon from 'sinon';


Expand Down
2 changes: 1 addition & 1 deletion src/lib/__tests__/main-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import expect from 'expect';

import instantsearch from '../main.js';
import forEach from 'lodash/collection/forEach';
import forEach from 'lodash/forEach';

describe('instantsearch()', () => {
// to ensure the global.window is set
Expand Down
2 changes: 1 addition & 1 deletion src/lib/__tests__/utils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import expect from 'expect';

import algoliasearchHelper from 'algoliasearch-helper';
import * as utils from '../utils';
import isEmpty from 'lodash/lang/isEmpty';
import isEmpty from 'lodash/isEmpty';

describe('utils.getContainerNode', () => {
it('should be able to get a node from a node', () => {
Expand Down
8 changes: 4 additions & 4 deletions src/lib/url-sync.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import algoliasearchHelper from 'algoliasearch-helper';
import version from '../lib/version.js';
import urlHelper from 'algoliasearch-helper/src/url';
import isEqual from 'lodash/lang/isEqual';
import merge from 'lodash/object/merge';/**/
import isEqual from 'lodash/isEqual';
import assign from 'lodash/assign';

const AlgoliaSearchHelper = algoliasearchHelper.AlgoliaSearchHelper;
const majorVersionNumber = version.split('.')[0];
Expand Down Expand Up @@ -123,7 +123,7 @@ class URLSync {
onPopState(helper, fullState) {
// compare with helper.state
const partialHelperState = helper.getState(this.trackedParameters);
const fullHelperState = merge({}, this.originalConfig, partialHelperState);
const fullHelperState = assign({}, this.originalConfig, partialHelperState);

if (isEqual(fullHelperState, fullState)) return;

Expand Down Expand Up @@ -175,7 +175,7 @@ class URLSync {
this.urlUtils.onpopstate(() => {
const qs = this.urlUtils.readUrl();
const partialState = AlgoliaSearchHelper.getConfigurationFromQueryString(qs, {mapping: this.mapping});
const fullState = merge({}, this.originalConfig, partialState);
const fullState = assign({}, this.originalConfig, partialState);
fn(fullState);
});
}
Expand Down
16 changes: 8 additions & 8 deletions src/lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import reduce from 'lodash/collection/reduce';
import forEach from 'lodash/collection/forEach';
import find from 'lodash/collection/find';
import get from 'lodash/object/get';
import isEmpty from 'lodash/lang/isEmpty';
import keys from 'lodash/object/keys';
import uniq from 'lodash/array/uniq';
import mapKeys from 'lodash/object/mapKeys';
import reduce from 'lodash/reduce';
import forEach from 'lodash/forEach';
import find from 'lodash/find';
import get from 'lodash/get';
import isEmpty from 'lodash/isEmpty';
import keys from 'lodash/keys';
import uniq from 'lodash/uniq';
import mapKeys from 'lodash/mapKeys';

export {
getContainerNode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import React from 'react';
import expect from 'expect';
import sinon from 'sinon';
import map from 'lodash/collection/map';
import filter from 'lodash/collection/filter';
import map from 'lodash/map';
import filter from 'lodash/filter';
import algoliasearch from 'algoliasearch';
import algoliasearchHelper from 'algoliasearch-helper';
import {prepareTemplateProps} from '../../../lib/utils';
Expand Down
20 changes: 10 additions & 10 deletions src/widgets/current-refined-values/current-refined-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import {
clearRefinementsAndSearch
} from '../../lib/utils.js';
import cx from 'classnames';
import isUndefined from 'lodash/lang/isUndefined';
import isBoolean from 'lodash/lang/isBoolean';
import isString from 'lodash/lang/isString';
import isArray from 'lodash/lang/isArray';
import isPlainObject from 'lodash/lang/isPlainObject';
import isFunction from 'lodash/lang/isFunction';
import isEmpty from 'lodash/lang/isEmpty';
import map from 'lodash/collection/map';
import reduce from 'lodash/collection/reduce';
import filter from 'lodash/collection/filter';
import isUndefined from 'lodash/isUndefined';
import isBoolean from 'lodash/isBoolean';
import isString from 'lodash/isString';
import isArray from 'lodash/isArray';
import isPlainObject from 'lodash/isPlainObject';
import isFunction from 'lodash/isFunction';
import isEmpty from 'lodash/isEmpty';
import map from 'lodash/map';
import reduce from 'lodash/reduce';
import filter from 'lodash/filter';
import headerFooterHOC from '../../decorators/headerFooter.js';
import autoHideContainerHOC from '../../decorators/autoHideContainer';
import defaultTemplates from './defaultTemplates';
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/hits-per-page-selector/hits-per-page-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
bemHelper,
getContainerNode
} from '../../lib/utils.js';
import any from 'lodash/collection/any';
import some from 'lodash/some';
import cx from 'classnames';
import autoHideContainerHOC from '../../decorators/autoHideContainer.js';
import SelectorComponent from '../../components/Selector.js';
Expand Down Expand Up @@ -57,7 +57,7 @@ function hitsPerPageSelector({

return {
init({helper, state}) {
const isCurrentInOptions = any(
const isCurrentInOptions = some(
options,
option => Number(state.hitsPerPage) === Number(option.value)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from 'react';
import expect from 'expect';
import sinon from 'sinon';

import cloneDeep from 'lodash/lang/cloneDeep';
import cloneDeep from 'lodash/cloneDeep';

import expectJSX from 'expect-jsx';
import numericRefinementList from '../numeric-refinement-list.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
getContainerNode
} from '../../lib/utils.js';
import cx from 'classnames';
import find from 'lodash/collection/find';
import includes from 'lodash/collection/includes';
import find from 'lodash/find';
import includes from 'lodash/includes';
import autoHideContainerHOC from '../../decorators/autoHideContainer.js';
import headerFooterHOC from '../../decorators/headerFooter.js';
import defaultTemplates from './defaultTemplates.js';
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/numeric-selector/numeric-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
getContainerNode
} from '../../lib/utils.js';
import cx from 'classnames';
import find from 'lodash/collection/find';
import find from 'lodash/find';
import autoHideContainerHOC from '../../decorators/autoHideContainer.js';
import SelectorComponent from '../../components/Selector.js';

Expand Down
2 changes: 1 addition & 1 deletion src/widgets/pagination/pagination.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import ReactDOM from 'react-dom';
import defaults from 'lodash/object/defaults';
import defaults from 'lodash/defaults';
import cx from 'classnames';
import {
bemHelper,
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/range-slider/range-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
prepareTemplateProps,
getContainerNode
} from '../../lib/utils.js';
import find from 'lodash/collection/find';
import find from 'lodash/find';
import autoHideContainerHOC from '../../decorators/autoHideContainer.js';
import headerFooterHOC from '../../decorators/headerFooter.js';
import cx from 'classnames';
Expand Down
Loading

0 comments on commit 216d1e0

Please sign in to comment.