Skip to content

Commit 28e1f0e

Browse files
committed
feat: remove lodash
1 parent db9d94c commit 28e1f0e

File tree

7 files changed

+223
-29
lines changed

7 files changed

+223
-29
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@
4343
]
4444
},
4545
"devDependencies": {
46-
"@types/lodash": "^4.14.115",
4746
"@types/react": "^16.4.7",
4847
"@types/react-dom": "^16.0.7",
4948
"husky": "^1.2.0",
5049
"less": "^3.9.0",
5150
"lint-staged": "^8.1.0",
5251
"normalize.css": "^8.0.1",
5352
"parcel-bundler": "^1.10.3",
53+
"parcel-plugin-bundle-visualiser": "^1.2.0",
5454
"prettier": "1.15.3",
5555
"react": "^16.4.2",
5656
"react-dom": "^16.4.2",
@@ -62,7 +62,6 @@
6262
"typescript": "^3.1.6"
6363
},
6464
"dependencies": {
65-
"lodash": "^4.17.11",
6665
"rxjs": "^6.3.3"
6766
},
6867
"peerDependencies": {

src/Bar.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import * as React from 'react';
2-
import { omit } from 'lodash';
32

4-
import { BarActionType, ChildProps, Coordinate, ExpandInteractiveArea } from './types';
3+
import {
4+
BarActionType,
5+
ChildProps,
6+
Coordinate,
7+
ExpandInteractiveArea,
8+
} from './types';
59
import { withResizerContext } from './context';
10+
import { omit } from './utils';
611

712
type Props = React.HTMLAttributes<HTMLDivElement> &
813
Pick<ChildProps, 'context' | 'size' | 'innerRef'> & {
@@ -60,8 +65,7 @@ class BarComponent extends React.PureComponent<Props> {
6065
}
6166

6267
private get renderProps() {
63-
return omit(
64-
this.props,
68+
return omit(this.props, [
6569
'expandInteractiveArea',
6670
'onStatusChanged',
6771
'children',
@@ -70,7 +74,7 @@ class BarComponent extends React.PureComponent<Props> {
7074
'innerRef',
7175
'context',
7276
'size',
73-
);
77+
]);
7478
}
7579

7680
private isActivated: boolean = false;

src/Container/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import * as React from 'react';
22
import { Subject, merge, animationFrameScheduler } from 'rxjs';
33
import { filter, share, observeOn, map } from 'rxjs/operators';
4-
import { omit } from 'lodash';
54

65
import {
76
BarAction,
87
ChildProps,
98
ResizerContext,
109
SizeRelatedInfo,
1110
} from '../types';
11+
import { omit } from '../utils';
1212
import { ResizerProvider } from '../context';
1313

1414
import { Resizer } from './Resizer';
@@ -79,7 +79,7 @@ class Container extends React.PureComponent<Props> {
7979
}
8080

8181
private get renderProps() {
82-
return omit(this.props, 'vertical', 'beforeApplyResizer');
82+
return omit(this.props, ['vertical', 'beforeApplyResizer']);
8383
}
8484

8585
private get contextValue(): ResizerContext {

src/Section.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import * as React from 'react';
2-
import { omit } from 'lodash';
32
import { Subscription } from 'rxjs';
43
import { filter, map, tap } from 'rxjs/operators';
54

65
import { ChildProps, SizeInfo } from './types';
76
import { withResizerContext } from './context';
8-
import { isValidNumber } from './utils';
7+
import { isValidNumber, omit } from './utils';
98

109
type Props = ChildProps & React.HTMLAttributes<HTMLDivElement>;
1110

@@ -59,8 +58,7 @@ class SectionComponent extends React.PureComponent<Props> {
5958
}
6059

6160
render() {
62-
const props = omit(
63-
this.props,
61+
const props = omit(this.props, [
6462
'innerRef',
6563
// ChildProps
6664
'defaultSize',
@@ -69,7 +67,7 @@ class SectionComponent extends React.PureComponent<Props> {
6967
'size',
7068
'minSize',
7169
'maxSize',
72-
);
70+
]);
7371

7472
const { vertical } = this.props.context;
7573

src/context.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as React from 'react';
2-
import { noop } from 'lodash';
2+
import { EMPTY } from 'rxjs';
33

44
import { Omit, ChildProps, ResizerContext } from './types';
5-
import { EMPTY } from 'rxjs';
5+
import { noop } from './utils';
66

77
export const {
88
Provider: ResizerProvider,

src/utils.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
1-
import { isFinite as _isFinite } from 'lodash';
2-
31
export function isValidNumber(num?: number): num is number {
4-
return _isFinite(num);
2+
return typeof num === 'number' && num === num;
3+
}
4+
5+
export function omit<T extends { [key in string]: any }>(
6+
obj: T,
7+
paths: string[],
8+
): T {
9+
const newObj = {} as T;
10+
11+
Object.keys(obj)
12+
.filter((path) => paths.indexOf(path) === -1)
13+
.forEach((path) => {
14+
newObj[path] = obj[path];
15+
});
16+
17+
return newObj;
518
}
19+
20+
export function noop() {}

0 commit comments

Comments
 (0)