Skip to content

Commit e3fb63e

Browse files
authored
Merge pull request #8 from Lodin/fix/optional-options
Allow calling recomputeTree without arguments
2 parents 2c2a009 + 4d3b900 commit e3fb63e

11 files changed

+3482
-4874
lines changed

.babelrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const isLib = BUILD_TYPE === 'lib';
55
module.exports = api => ({
66
plugins: [
77
[require('@babel/plugin-proposal-class-properties'), {loose: true}],
8+
[require('@babel/plugin-proposal-optional-chaining'), {loose: true}],
89
...(isLib
910
? []
1011
: [

__stories__/FixedSizeTree.story.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const defaultButtonStyle = {fontFamily: 'Courier New'};
6060

6161
function* treeWalker(
6262
refresh: boolean,
63-
): IterableIterator<FixedSizeNodeData<ExtendedData> | string | symbol> {
63+
): Generator<FixedSizeNodeData<ExtendedData> | string | symbol, void, boolean> {
6464
const stack: StackElement[] = [];
6565

6666
stack.push({
@@ -94,9 +94,9 @@ function* treeWalker(
9494
}
9595
}
9696

97-
const Node: React.FunctionComponent<
98-
FixedSizeNodeComponentProps<ExtendedData>
99-
> = ({data: {isLeaf, name, nestingLevel}, isOpen, style, toggle}) => (
97+
const Node: React.FunctionComponent<FixedSizeNodeComponentProps<
98+
ExtendedData
99+
>> = ({data: {isLeaf, name, nestingLevel}, isOpen, style, toggle}) => (
100100
<div
101101
style={{
102102
...style,

__stories__/VariableSizeTree.story.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ const rootNode = createNode();
5858
const defaultGapStyle = {marginLeft: 10};
5959
const defaultButtonStyle = {fontFamily: 'Courier New'};
6060

61-
const Node: React.FunctionComponent<
62-
VariableSizeNodeComponentProps<ExtendedData>
63-
> = ({
61+
const Node: React.FunctionComponent<VariableSizeNodeComponentProps<
62+
ExtendedData
63+
>> = ({
6464
height,
6565
data: {isLeaf, name, nestingLevel},
6666
isOpen,
@@ -116,7 +116,11 @@ const TreePresenter: React.FunctionComponent<TreePresenterProps> = ({
116116
const treeWalker = React.useCallback(
117117
function*(
118118
refresh: boolean,
119-
): IterableIterator<VariableSizeNodeData<ExtendedData> | string | symbol> {
119+
): Generator<
120+
VariableSizeNodeData<ExtendedData> | string | symbol,
121+
void,
122+
boolean
123+
> {
120124
const stack: StackElement[] = [];
121125

122126
stack.push({
@@ -154,9 +158,7 @@ const TreePresenter: React.FunctionComponent<TreePresenterProps> = ({
154158
);
155159

156160
React.useEffect(() => {
157-
if (tree.current) {
158-
tree.current!.recomputeTree({refreshNodes: true, useDefaultHeight: true});
159-
}
161+
tree.current?.recomputeTree({refreshNodes: true, useDefaultHeight: true});
160162
}, [itemSize]);
161163

162164
return (

__tests__/FixedSizeTree.spec.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ type ExtendedData = {
2626
};
2727

2828
describe('FixedSizeTree', () => {
29-
const Node: React.FunctionComponent<
30-
FixedSizeNodeComponentProps<ExtendedData>
31-
> = () => null;
29+
const Node: React.FunctionComponent<FixedSizeNodeComponentProps<
30+
ExtendedData
31+
>> = () => null;
3232

3333
let component: ReactWrapper<
3434
FixedSizeTreeProps<ExtendedData>,
@@ -41,7 +41,10 @@ describe('FixedSizeTree', () => {
4141

4242
beforeEach(() => {
4343
tree = {
44-
children: [{id: 'foo-2', name: 'Foo #2'}, {id: 'foo-3', name: 'Foo #3'}],
44+
children: [
45+
{id: 'foo-2', name: 'Foo #2'},
46+
{id: 'foo-3', name: 'Foo #3'},
47+
],
4548
id: 'foo-1',
4649
name: 'Foo #1',
4750
};
@@ -196,7 +199,7 @@ describe('FixedSizeTree', () => {
196199
name: 'Foo #1',
197200
};
198201

199-
await treeInstance.recomputeTree({refreshNodes: false});
202+
await treeInstance.recomputeTree();
200203
component.update(); // update the wrapper to get the latest changes
201204

202205
expect(component.find(FixedSizeList).prop('itemData')).toMatchObject({

__tests__/VariableSizeTree.spec.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ type ExtendedData = {
2626
};
2727

2828
describe('VariableSizeTree', () => {
29-
const Node: React.FunctionComponent<
30-
VariableSizeNodeComponentProps<ExtendedData>
31-
> = () => null;
29+
const Node: React.FunctionComponent<VariableSizeNodeComponentProps<
30+
ExtendedData
31+
>> = () => null;
3232

3333
let component: ReactWrapper<
3434
VariableSizeTreeProps<ExtendedData>,
@@ -42,7 +42,10 @@ describe('VariableSizeTree', () => {
4242

4343
beforeEach(() => {
4444
tree = {
45-
children: [{id: 'foo-2', name: 'Foo #2'}, {id: 'foo-3', name: 'Foo #3'}],
45+
children: [
46+
{id: 'foo-2', name: 'Foo #2'},
47+
{id: 'foo-3', name: 'Foo #3'},
48+
],
4649
id: 'foo-1',
4750
name: 'Foo #1',
4851
};
@@ -212,7 +215,7 @@ describe('VariableSizeTree', () => {
212215
name: 'Foo #1',
213216
};
214217

215-
await treeInstance.recomputeTree({refreshNodes: false});
218+
await treeInstance.recomputeTree();
216219
component.update(); // update the wrapper to get the latest changes
217220

218221
expect(component.find(VariableSizeList).prop('itemData')).toMatchObject(

0 commit comments

Comments
 (0)