Skip to content

Commit

Permalink
Wrap lodash functions to avoid exporting lodash type defs (#1723)
Browse files Browse the repository at this point in the history
* Wrap lodash functions to avoid exporting lodash type defs

* changelog
  • Loading branch information
chandlerprall authored Mar 13, 2019
1 parent b92fa19 commit a54ab16
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

- Allow toasts in `EuiGlobalToastList` to override `toastLifeTimeMs` ([#1720](https://github.com/elastic/eui/pull/1720))

**Bug fixes**

- Removed all `lodash` imports in `eui.d.ts` to avoid namespace pollution ([#1723](https://github.com/elastic/eui/pull/1723))

## [`9.3.0`](https://github.com/elastic/eui/tree/v9.3.0)

- Added `footerLink` and `showToolTips` to `EuiNavDrawer` and added `EuiNavDrawerGroup` ([#1701](https://github.com/elastic/eui/pull/1701))
Expand Down
13 changes: 10 additions & 3 deletions src/services/objects.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import get from 'lodash/get';
import omit from 'lodash/omit';
import _get from 'lodash/get';
import _omit from 'lodash/omit';

export { get, omit };
// wrap the lodash functions to avoid having lodash's TS type definition from being
// exported, which can conflict with the lodash namespace if other versions are used

export const get = (object: {}, path: string[] | string, defaultValue?: any) =>
_get(object, path, defaultValue);

export const omit = (object: {} | null | undefined, paths: string[]) =>
_omit(object, paths);
23 changes: 16 additions & 7 deletions src/services/predicate/lodash_predicates.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import isFunction from 'lodash/isFunction';
import isArray from 'lodash/isArray';
import isString from 'lodash/isString';
import isBoolean from 'lodash/isBoolean';
import isNumber from 'lodash/isNumber';
import isNaN from 'lodash/isNaN';
import _isFunction from 'lodash/isFunction';
import _isArray from 'lodash/isArray';
import _isString from 'lodash/isString';
import _isBoolean from 'lodash/isBoolean';
import _isNumber from 'lodash/isNumber';
import _isNaN from 'lodash/isNaN';

export { isFunction, isArray, isString, isBoolean, isNumber, isNaN };
// wrap the lodash functions to avoid having lodash's TS type definition from being
// exported, which can conflict with the lodash namespace if other versions are used

// tslint:disable-next-line:ban-types
export const isFunction = (value: any): value is Function => _isFunction(value);
export const isArray = (value: any): value is any[] => _isArray(value);
export const isString = (value: any): value is string => _isString(value);
export const isBoolean = (value: any): value is boolean => _isBoolean(value);
export const isNumber = (value: any): value is number => _isNumber(value);
export const isNaN = (value: any) => _isNaN(value);
23 changes: 20 additions & 3 deletions src/services/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
import times from 'lodash/times';
import memoize from 'lodash/memoize';
import _times from 'lodash/times';
import _memoize from 'lodash/memoize';

export { times, memoize };
// wrap the lodash functions to avoid having lodash's TS type definition from being
// exported, which can conflict with the lodash namespace if other versions are used

export function times<T>(count: number): number[];
export function times<T>(count: number, iteratee: (index: number) => T): T[];
export function times<T>(count: number, iteratee?: (index: number) => T) {
if (iteratee === undefined) {
return _times(count);
}
return _times(count, iteratee);
}

export function memoize<T extends (...args: any[]) => any>(
func: T,
resolver?: (...args: any[]) => any
): (...args: Parameters<T>) => ReturnType<T> {
return _memoize(func, resolver);
}

export const browserTick = (callback: FrameRequestCallback) => {
requestAnimationFrame(callback);
Expand Down

0 comments on commit a54ab16

Please sign in to comment.