Skip to content

Commit 5bc9cb9

Browse files
committed
chore: remove uneccessary dependencies
1 parent 58525c9 commit 5bc9cb9

8 files changed

Lines changed: 64 additions & 279 deletions

File tree

‎.eslintrc.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
extends: '@ecomfe/eslint-config/strict',
3-
plugins: ['jest'],
3+
plugins: ['jest', 'react-hooks'],
44
env: {
55
'jest/globals': true
66
},
@@ -13,6 +13,8 @@ module.exports = {
1313
'import/no-unresolved': [
1414
'error',
1515
{ignore: ['react-diff-view']}
16-
]
16+
],
17+
'react-hooks/rules-of-hooks': 'error',
18+
'react-hooks/exhaustive-deps': 'error'
1719
}
1820
};

‎package.json‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"license": "MIT",
2424
"dependencies": {
2525
"classnames": "^2.2.6",
26-
"core-js": "^3.3.4",
2726
"diff-match-patch": "^1.0.4",
2827
"recompose": "^0.30.0",
2928
"shallow-equal": "^1.2.0",
@@ -47,7 +46,7 @@
4746
"babel-plugin-import": "^1.12.2",
4847
"babel-plugin-lodash": "^3.3.4",
4948
"babel-plugin-react-require": "^3.0.1",
50-
"copy-webpack-plugin": "^5.0.4",
49+
"core-js": "^3.3.4",
5150
"css-loader": "^3.2.0",
5251
"enzyme": "^3.10.0",
5352
"enzyme-adapter-react-16": "^1.15.1",
@@ -56,26 +55,22 @@
5655
"eslint-plugin-import": "^2.18.2",
5756
"eslint-plugin-jest": "^22.21.0",
5857
"eslint-plugin-react": "^7.16.0",
58+
"eslint-plugin-react-hooks": "^2.2.0",
5959
"gitdiff-parser": "^0.1.2",
6060
"html-webpack-plugin": "^3.0.6",
6161
"identity-obj-proxy": "^3.0.0",
6262
"jest": "^24.9.0",
6363
"less": "^3.10.3",
6464
"less-loader": "^5.0.0",
6565
"lodash": "^4.17.15",
66-
"lodash-decorators": "^6.0.1",
67-
"prism-themes": "^1.3.0",
6866
"raw-loader": "^3.1.0",
6967
"react": "^16.11.0",
7068
"react-dom": "^16.11.0",
7169
"react-infinite-scroller": "^1.2.4",
72-
"react-kiss": "^1.2.0",
7370
"react-markdown": "^4.2.2",
7471
"react-test-renderer": "^16.11.0",
7572
"react-timeago": "^4.1.9",
76-
"react-whether": "^1.0.1",
7773
"refractor": "^2.10.0",
78-
"reselect": "^4.0.0",
7974
"rollup": "^1.25.2",
8075
"rollup-plugin-auto-external": "^2.0.0",
8176
"rollup-plugin-babel": "^4.3.3",
@@ -87,10 +82,7 @@
8782
"rollup-plugin-sourcemaps": "^0.4.2",
8883
"rollup-plugin-terser": "^5.1.2",
8984
"sha1": "^1.1.1",
90-
"shallow-changes": "^1.0.2",
91-
"short-hash": "^1.0.0",
9285
"style-loader": "^1.0.0",
93-
"svg-react-loader": "^0.4.6",
9486
"unidiff": "^1.0.2",
9587
"webpack": "^4.41.2",
9688
"webpack-cli": "^3.3.9",

‎site/components/DiffView/Unfold.js‎

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import {PureComponent} from 'react';
1+
import {useCallback} from 'react';
22
import {Icon} from 'antd';
3-
import {bind} from 'lodash-decorators';
43
import {Decoration} from 'react-diff-view';
54
import styles from './Unfold.less';
65

@@ -10,26 +9,23 @@ const ICON_TYPE_MAPPING = {
109
none: 'plus-circle',
1110
};
1211

13-
export default class Unfold extends PureComponent {
12+
const Unfold = ({start, end, direction, onExpand, ...props}) => {
13+
const expand = useCallback(
14+
() => onExpand(start, end),
15+
[onExpand, start, end]
16+
);
1417

15-
@bind()
16-
expand() {
17-
const {start, end, onExpand} = this.props;
18-
onExpand(start, end);
19-
}
18+
const iconType = ICON_TYPE_MAPPING[direction];
19+
const lines = end - start;
2020

21-
render() {
22-
const {start, end, direction, ...props} = this.props;
23-
const iconType = ICON_TYPE_MAPPING[direction];
24-
const lines = end - start;
21+
return (
22+
<Decoration {...props}>
23+
<div className={styles.root} onClick={expand}>
24+
<Icon type={iconType} />
25+
&nbsp;Expand hidden {lines} lines
26+
</div>
27+
</Decoration>
28+
);
29+
};
2530

26-
return (
27-
<Decoration {...props}>
28-
<div className={styles.root} onClick={this.expand}>
29-
<Icon type={iconType} />
30-
&nbsp;Expand hidden {lines} lines
31-
</div>
32-
</Decoration>
33-
);
34-
}
35-
}
31+
export default Unfold;

‎site/components/DiffView/UnfoldCollapsed.js‎

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import {Fragment} from 'react';
2-
import {Whether} from 'react-whether';
31
import {getCollapsedLinesCountBetween} from 'react-diff-view';
42
import Unfold from './Unfold';
53

@@ -13,12 +11,19 @@ const UnfoldCollapsed = ({previousHunk, currentHunk, linesCount, onExpand}) => {
1311
}
1412

1513
return (
16-
<Fragment>
17-
<Whether matches={collapsedLines > 10}>
18-
<Unfold direction="down" start={nextStart} end={nextStart + 10} onExpand={onExpand} />
19-
</Whether>
14+
<>
15+
{
16+
collapsedLines > 10 && (
17+
<Unfold
18+
direction="down"
19+
start={nextStart}
20+
end={nextStart + 10}
21+
onExpand={onExpand}
22+
/>
23+
)
24+
}
2025
<Unfold direction="none" start={nextStart} end={linesCount + 1} onExpand={onExpand} />
21-
</Fragment>
26+
</>
2227
);
2328
}
2429

@@ -32,12 +37,19 @@ const UnfoldCollapsed = ({previousHunk, currentHunk, linesCount, onExpand}) => {
3237
const start = Math.max(currentHunk.oldStart - 10, 1);
3338

3439
return (
35-
<Fragment>
40+
<>
3641
<Unfold direction="none" start={1} end={currentHunk.oldStart} onExpand={onExpand} />
37-
<Whether matches={collapsedLines > 10}>
38-
<Unfold direction="up" start={start} end={currentHunk.oldStart} onExpand={onExpand} />
39-
</Whether>
40-
</Fragment>
42+
{
43+
collapsedLines > 10 && (
44+
<Unfold
45+
direction="up"
46+
start={start}
47+
end={currentHunk.oldStart}
48+
onExpand={onExpand}
49+
/>
50+
)
51+
}
52+
</>
4153
);
4254
}
4355

@@ -51,11 +63,11 @@ const UnfoldCollapsed = ({previousHunk, currentHunk, linesCount, onExpand}) => {
5163
}
5264

5365
return (
54-
<Fragment>
66+
<>
5567
<Unfold direction="down" start={collapsedStart} end={collapsedStart + 10} onExpand={onExpand} />
5668
<Unfold direction="none" start={collapsedStart} end={collapsedEnd} onExpand={onExpand} />
5769
<Unfold direction="up" start={collapsedEnd - 10} end={collapsedEnd} onExpand={onExpand} />
58-
</Fragment>
70+
</>
5971
);
6072
};
6173

‎src/Hunk/SplitHunk/SplitChange.js‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,17 @@ const SIDE_NEW = 1;
1313
const useCallbackOnSide = (side, setHover, change, customCallbacks) => {
1414
const markHover = useCallback(() => setHover(side), [side, setHover]);
1515
const unmarkHover = useCallback(() => setHover(''), [setHover]);
16-
const arg = {side, change};
1716
// Unlike selectors, hooks do not provide native functionality to customize comparator,
1817
// on realizing that this does not reduce amount of renders, only preventing duplicate merge computations,
1918
// we decide not to optimize this extremely, leave it recomputed on certain rerenders.
2019
const callbacks = useMemo(
2120
() => {
22-
const callbacks = mapValues(customCallbacks, fn => () => fn(arg));
21+
const callbacks = mapValues(customCallbacks, fn => () => fn({side, change}));
2322
callbacks.onMouseEnter = composeCallback(markHover, callbacks.onMouseEnter);
2423
callbacks.onMouseLeave = composeCallback(unmarkHover, callbacks.onMouseLeave);
2524
return callbacks;
2625
},
27-
[change, customCallbacks, markHover, unmarkHover]
26+
[change, customCallbacks, markHover, side, unmarkHover]
2827
);
2928
return callbacks;
3029
};

‎src/Hunk/UnifiedHunk/UnifiedChange.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const useBoundCallbacks = (callbacks, arg, hoverOn, hoverOff) => useMemo(
1414
output.onMouseLeave = composeCallback(hoverOff, output.onMouseLeave);
1515
return output;
1616
},
17-
[callbacks, arg]
17+
[callbacks, hoverOn, hoverOff, arg]
1818
);
1919

2020
const useBoolean = () => {

‎src/hooks/useTokenizeWorker.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export default (worker, payload, options = {}) => {
7373
};
7474
worker.postMessage(data);
7575
},
76-
// eslint-disable-next-line: react-hooks/exhaustive-deps
76+
// eslint-disable-next-line react-hooks/exhaustive-deps
7777
[payloadIdentifier, worker, shouldTokenize] // TODO: How about worker changes when payload keeps identical?
7878
);
7979

0 commit comments

Comments
 (0)