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

Downgraded lodash 3.10.1 (to align with Kibana) #359

Merged
merged 1 commit into from
Feb 1, 2018
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

No public interface changes since `0.0.16`.

**Bug fixes**

- downgraded `lodash` version to `3.10.0` to align it with Kibana

# [`0.0.16`](https://github.com/elastic/eui/tree/v0.0.16)

- `EuiRadio` now supports the `input` tag's `name` attribute. `EuiRadioGroup` accepts a `name` prop that will propagate to its `EuiRadio`s. ([#348](https://github.com/elastic/eui/pull/348))
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"html": "^1.0.0",
"jquery": "^3.2.1",
"keymirror": "^0.1.1",
"lodash": "^4.17.4",
"lodash": "^3.10.1",
"numeral": "^2.0.6",
"prop-types": "^15.6.0",
"react-ace": "^5.5.0",
Expand Down Expand Up @@ -74,7 +74,6 @@
"html-webpack-plugin": "^2.30.1",
"jest": "^22.0.6",
"jest-cli": "^22.0.6",
"lodash": "^4.17.4",
"moment": "2.13.0",
"node-sass": "^4.5.3",
"npm-run": "^4.1.2",
Expand Down
2 changes: 1 addition & 1 deletion src/components/table_of_records/default_record_action.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { isString } from 'lodash';
import { isString } from '../../services/predicate';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we export the predicates from the root modules, services?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can... thought about it... decided not to... but I can still do that.

Why decided not to? With generic services it somewhat feels off to export ALL possible utility functions under one module. the services sub-modules really don't have anything in common aside from the fact that they're all a bunch of utilities. To me it feels more appropriate to refer to the specific module when importing utilities.

But... that's my opinion... if you insist I can still export all to the higher services module

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right. In fact we should probably apply this pattern to the rest of the submodules under services.

import { EuiButton, EuiButtonIcon } from '../button';

const defaults = {
Expand Down
3 changes: 2 additions & 1 deletion src/components/table_of_records/table_of_records.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import _ from 'lodash';
import { isString } from '../../services/predicate';
import classNames from 'classnames';
import PropTypes from 'prop-types';
import {
Expand Down Expand Up @@ -162,7 +163,7 @@ export class EuiTableOfRecords extends React.Component {

recordId(record) {
const id = this.props.config.recordId;
return _.isString(id) ? record[id] : id(record);
return isString(id) ? record[id] : id(record);
}

changeSelection(selection) {
Expand Down
2 changes: 1 addition & 1 deletion src/services/format/format_auto.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isArray, isBoolean, isDate, isNaN, isNil, isNumber, isString } from 'lodash';
import { isNil, isArray, isBoolean, isDate, isNaN, isNumber, isString } from '../predicate';
import { formatBoolean } from './format_boolean';
import { formatDate } from './format_date';
import { formatNumber } from './format_number';
Expand Down
2 changes: 1 addition & 1 deletion src/services/format/format_boolean.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isNil } from 'lodash';
import { isNil } from '../predicate';

export const formatBoolean = (value, { yes = 'Yes', no = 'No', nil = '' } = {}) => {
if (isNil(value)) {
Expand Down
2 changes: 1 addition & 1 deletion src/services/format/format_date.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isNil, isFunction, isString } from 'lodash';
import { isNil, isFunction, isString } from '../predicate';
import moment from 'moment';

const calendar = (value, options = {}) => {
Expand Down
2 changes: 1 addition & 1 deletion src/services/format/format_number.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numeral from 'numeral';
import { isNil, isString } from 'lodash';
import { isNil, isString } from '../predicate';

const numberFormatAliases = {
decimal1: '0,0.0',
Expand Down
2 changes: 1 addition & 1 deletion src/services/format/format_text.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isNil } from 'lodash';
import { isNil } from '../predicate';

export const formatText = (value, { nil = '' } = {}) => {
return isNil(value) ? nil : value.toString();
Expand Down
15 changes: 15 additions & 0 deletions src/services/predicate/common_predicates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export const always = () => true;

export const never = () => false;

export const isUndefined = (value) => {
return value === undefined;
};

export const isNull = (value) => {
return value === null;
};

export const isNil = (value) => {
return isUndefined(value) || isNull(value);
};
44 changes: 44 additions & 0 deletions src/services/predicate/common_predicates.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { always, never, isNil, isUndefined, isNull } from './common_predicates';

describe('common predicates', () => {

test('always', () => {
[ undefined, null, 'a', 1, true, false, Date.now(), {}, [], /.*/ ].forEach(value => {
expect(always(value)).toBe(true);
});
});

test('never', () => {
[ undefined, null, 'a', 1, true, false, Date.now(), {}, [], /.*/ ].forEach(value => {
expect(never(value)).toBe(false);
});
});

test('isUndefined', () => {
[ undefined ].forEach(value => {
expect(isUndefined(value)).toBe(true);
});
[ null, 'a', 1, true, false, Date.now(), {}, [], /.*/ ].forEach(value => {
expect(isUndefined(value)).toBe(false);
});
});

test('isNull', () => {
[ null ].forEach(value => {
expect(isNull(value)).toBe(true);
});
[ undefined, 'a', 1, true, false, Date.now(), {}, [], /.*/ ].forEach(value => {
expect(isNull(value)).toBe(false);
});
});

test('isNil', () => {
[ undefined, null ].forEach(value => {
expect(isNil(value)).toBe(true);
});
[ 'a', 1, true, false, Date.now(), {}, [], /.*/ ].forEach(value => {
expect(isNil(value)).toBe(false);
});
});

});
2 changes: 2 additions & 0 deletions src/services/predicate/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './common_predicates';
export * from './lodash_predicates';
9 changes: 9 additions & 0 deletions src/services/predicate/lodash_predicates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export {
isFunction,
isArray,
isString,
isBoolean,
isDate,
isNumber,
isNaN,
} from 'lodash';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not remove lodash entirely? Can we internalize these functions?

Copy link
Contributor Author

@uboness uboness Feb 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should... but it'll have to wait to a different pr... (there's more to this when it comes to removing lodash... we'll need to remove other usages as well - e.g. _.get)

2 changes: 1 addition & 1 deletion src/services/random.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isNil } from 'lodash';
import { isNil } from './predicate';

const defaultRand = Math.random;

Expand Down
10 changes: 7 additions & 3 deletions src/services/sort/comparators.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ export const Comparators = Object.freeze({
return (v1, v2) => comparator(v2, v1);
},

property(prop, comparator = undefined) {
value(valueCallback, comparator = undefined) {
if (!comparator) {
comparator = this.default(SortDirection.ASC);
}
return (o1, o2) => {
return comparator(o1[prop], o2[prop]);
return comparator(valueCallback(o1), valueCallback(o2));
};
}
},

property(prop, comparator = undefined) {
return this.value(value => value[prop], comparator);
},

});
12 changes: 8 additions & 4 deletions src/services/sort/sortable_properties.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import sortBy from 'lodash/sortBy';
import { Comparators } from './comparators';

/**
* @typedef {Object} SortableProperty
Expand Down Expand Up @@ -43,9 +43,13 @@ export class SortableProperties {
* @returns {Array.<Object>} sorted array of items, based off the sort properties.
*/
sortItems(items) {
return this.isCurrentSortAscending()
? sortBy(items, this.getSortedProperty().getValue)
: sortBy(items, this.getSortedProperty().getValue).reverse();
const copy = [...items];
let comparator = Comparators.value(this.getSortedProperty().getValue);
if (!this.isCurrentSortAscending()) {
comparator = Comparators.reverse(comparator);
}
copy.sort(comparator);
return copy;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/utils/prop_types/is.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isNil } from 'lodash';
import { isNil } from '../../services/predicate';

export const is = (expectedValue) => {

Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5295,7 +5295,7 @@ lodash.uniq@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"

lodash@^3.3.1:
lodash@^3.10.1, lodash@^3.3.1:
version "3.10.1"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6"

Expand Down