Skip to content

Commit

Permalink
Remove lodash.throttle and replace underscore calls with lodash (#5946)
Browse files Browse the repository at this point in the history
* remove lodash.throttle from dependency

* add babel-plugin-lodash'

* use lodash instead of underscore for isFunction

* switch underscore to lodash

* switch from underscore to lodash flatten

* Remove slugify and use kebabCase from lodash instead
  • Loading branch information
kristw authored and mistercrunch committed Sep 27, 2018
1 parent 52033cb commit 4c21c65
Show file tree
Hide file tree
Showing 15 changed files with 19 additions and 41 deletions.
2 changes: 1 addition & 1 deletion superset/assets/.babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"presets" : ["airbnb", "react", "env"],
"plugins": ["syntax-dynamic-import", "react-hot-loader/babel"]
"plugins": ["lodash", "syntax-dynamic-import", "react-hot-loader/babel"]
}
2 changes: 1 addition & 1 deletion superset/assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
"jquery": "3.1.1",
"json-bigint": "^0.3.0",
"lodash": "^4.17.11",
"lodash.throttle": "^4.1.1",
"mapbox-gl": "^0.45.0",
"mathjs": "^3.20.2",
"moment": "^2.20.1",
Expand Down Expand Up @@ -138,6 +137,7 @@
"babel-loader": "^7.1.4",
"babel-plugin-css-modules-transform": "^1.1.0",
"babel-plugin-dynamic-import-node": "^1.2.0",
"babel-plugin-lodash": "^3.3.4",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
"babel-polyfill": "^6.23.0",
"babel-preset-airbnb": "^2.1.1",
Expand Down
7 changes: 0 additions & 7 deletions superset/assets/spec/javascripts/modules/utils_spec.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { expect, assert } from 'chai';
import {
slugify,
formatSelectOptionsForRange,
d3format,
d3FormatPreset,
Expand All @@ -10,12 +9,6 @@ import {
} from '../../../src/modules/utils';

describe('utils', () => {
it('slugify slugifies', () => {
expect(slugify('My Neat Label! ')).to.equal('my-neat-label');
expect(slugify('Some Letters AnD a 5')).to.equal('some-letters-and-a-5');
expect(slugify(' 439278 ')).to.equal('439278');
expect(slugify('5')).to.equal('5');
});
it('formatSelectOptionsForRange', () => {
expect(formatSelectOptionsForRange(0, 4)).to.deep.equal([
[0, '0'],
Expand Down
2 changes: 1 addition & 1 deletion superset/assets/src/SqlLab/components/SqlEditor.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import throttle from 'lodash.throttle';
import { throttle } from 'lodash';
import {
Col,
FormGroup,
Expand Down
2 changes: 1 addition & 1 deletion superset/assets/src/components/AlteredSliceTag.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Table, Tr, Td, Thead, Th } from 'reactable';
import { isEqual, isEmpty } from 'underscore';
import { isEqual, isEmpty } from 'lodash';

import TooltipWrapper from './TooltipWrapper';
import { controls } from '../explore/controls';
Expand Down
4 changes: 2 additions & 2 deletions superset/assets/src/components/Button.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import { kebabCase } from 'lodash';
import { Button as BootstrapButton, Tooltip, OverlayTrigger } from 'react-bootstrap';
import { slugify } from '../modules/utils';

const propTypes = {
tooltip: PropTypes.node,
Expand Down Expand Up @@ -41,7 +41,7 @@ export default function Button(props) {
return (
<OverlayTrigger
placement={placement}
overlay={<Tooltip id={`${slugify(tooltip)}-tooltip`}>{tooltip}</Tooltip>}
overlay={<Tooltip id={`${kebabCase(tooltip)}-tooltip`}>{tooltip}</Tooltip>}
>
{button}
</OverlayTrigger>
Expand Down
4 changes: 2 additions & 2 deletions superset/assets/src/components/InfoTooltipWithTrigger.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import { kebabCase } from 'lodash';
import { Tooltip, OverlayTrigger } from 'react-bootstrap';
import { slugify } from '../modules/utils';

const propTypes = {
label: PropTypes.string.isRequired,
Expand Down Expand Up @@ -36,7 +36,7 @@ export default function InfoTooltipWithTrigger({
<OverlayTrigger
placement={placement}
overlay={
<Tooltip id={`${slugify(label)}-tooltip`} style={tooltipStyle}>
<Tooltip id={`${kebabCase(label)}-tooltip`} style={tooltipStyle}>
{tooltip}
</Tooltip>
}
Expand Down
4 changes: 2 additions & 2 deletions superset/assets/src/components/TooltipWrapper.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import { kebabCase } from 'lodash';
import { Tooltip, OverlayTrigger } from 'react-bootstrap';
import { slugify } from '../modules/utils';

const propTypes = {
label: PropTypes.string.isRequired,
Expand All @@ -18,7 +18,7 @@ export default function TooltipWrapper({ label, tooltip, children, placement })
return (
<OverlayTrigger
placement={placement}
overlay={<Tooltip id={`${slugify(label)}-tooltip`}>{tooltip}</Tooltip>}
overlay={<Tooltip id={`${kebabCase(label)}-tooltip`}>{tooltip}</Tooltip>}
>
{children}
</OverlayTrigger>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import throttle from 'lodash.throttle';
import { throttle } from 'lodash';
import getDropPosition from '../../util/getDropPosition';

const HOVER_THROTTLE_MS = 100;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import _ from 'underscore';
import { isFunction } from 'lodash';
import { Creatable } from 'react-select';
import ControlHeader from '../ControlHeader';
import { colorScalerFactory } from '../../../modules/colors';
Expand Down Expand Up @@ -48,7 +48,7 @@ export default class ColorSchemeControl extends React.PureComponent {

renderOption(key) {
const { schemes } = this.props;
const schemeLookup = _.isFunction(schemes) ? schemes() : schemes;
const schemeLookup = isFunction(schemes) ? schemes() : schemes;
const currentScheme = schemeLookup[key.value || defaultProps.value];

let colors = currentScheme;
Expand All @@ -68,7 +68,7 @@ export default class ColorSchemeControl extends React.PureComponent {

render() {
const { choices } = this.props;
const options = (_.isFunction(choices) ? choices() : choices)
const options = (isFunction(choices) ? choices() : choices)
.map(choice => ({ value: choice[0], label: choice[1] }));

const selectProps = {
Expand Down
11 changes: 0 additions & 11 deletions superset/assets/src/modules/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint camelcase: 0 */
import d3 from 'd3';
import $ from 'jquery';

import { formatDate, UTC } from './dates';

const siFormatter = d3.format('.3s');
Expand Down Expand Up @@ -186,16 +185,6 @@ export function formatSelectOptions(options) {
);
}

export function slugify(string) {
// slugify('My Neat Label! '); returns 'my-neat-label'
return string
.toString()
.toLowerCase()
.trim()
.replace(/[\s\W-]+/g, '-') // replace spaces, non-word chars, w/ a single dash (-)
.replace(/-$/, ''); // remove last floating dash
}

export function getAjaxErrorMsg(error) {
const respJSON = error.responseJSON;
return (respJSON && respJSON.error) ? respJSON.error :
Expand Down
2 changes: 1 addition & 1 deletion superset/assets/src/reduxUtils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import shortid from 'shortid';
import { compose } from 'redux';
import persistState from 'redux-localstorage';
import { isEqual } from 'underscore';
import { isEqual } from 'lodash';

export function addToObject(state, arrKey, obj) {
const newObject = Object.assign({}, state[arrKey]);
Expand Down
4 changes: 2 additions & 2 deletions superset/assets/src/visualizations/deckgl/layers/polygon.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import ReactDOM from 'react-dom';

import { PolygonLayer } from 'deck.gl';
import _ from 'underscore';
import { flatten } from 'lodash';
import d3 from 'd3';

import DeckGLContainer from './../DeckGLContainer';
Expand All @@ -12,7 +12,7 @@ import { colorScalerFactory } from '../../../modules/colors';
import sandboxedEval from '../../../modules/sandbox';

function getPoints(features) {
return _.flatten(features.map(d => d.polygon), true);
return flatten(features.map(d => d.polygon), true);
}

function getLayer(formData, payload, slice) {
Expand Down
2 changes: 1 addition & 1 deletion superset/assets/src/visualizations/nvd3/NVD3Vis.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import throttle from 'lodash.throttle';
import { throttle } from 'lodash';
import d3 from 'd3';
import nv from 'nvd3';
import mathjs from 'mathjs';
Expand Down
6 changes: 1 addition & 5 deletions superset/assets/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1671,7 +1671,7 @@ babel-plugin-dynamic-import-node@^1.2.0:
dependencies:
babel-plugin-syntax-dynamic-import "^6.18.0"

babel-plugin-lodash@^3.3.2:
babel-plugin-lodash@^3.3.2, babel-plugin-lodash@^3.3.4:
version "3.3.4"
resolved "https://registry.yarnpkg.com/babel-plugin-lodash/-/babel-plugin-lodash-3.3.4.tgz#4f6844358a1340baed182adbeffa8df9967bc196"
dependencies:
Expand Down Expand Up @@ -7467,10 +7467,6 @@ lodash.once@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/lodash.once/-/lodash.once-4.1.1.tgz#0dd3971213c7c56df880977d504c88fb471a97ac"

lodash.throttle@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/lodash.throttle/-/lodash.throttle-4.1.1.tgz#c23e91b710242ac70c37f1e1cda9274cc39bf2f4"

lodash.union@~4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash.union/-/lodash.union-4.6.0.tgz#48bb5088409f16f1821666641c44dd1aaae3cd88"
Expand Down

0 comments on commit 4c21c65

Please sign in to comment.