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

Allow calling recomputeTree without arguments #8

Merged
merged 2 commits into from
Dec 4, 2019
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
1 change: 1 addition & 0 deletions .babelrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const isLib = BUILD_TYPE === 'lib';
module.exports = api => ({
plugins: [
[require('@babel/plugin-proposal-class-properties'), {loose: true}],
[require('@babel/plugin-proposal-optional-chaining'), {loose: true}],
...(isLib
? []
: [
Expand Down
8 changes: 4 additions & 4 deletions __stories__/FixedSizeTree.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const defaultButtonStyle = {fontFamily: 'Courier New'};

function* treeWalker(
refresh: boolean,
): IterableIterator<FixedSizeNodeData<ExtendedData> | string | symbol> {
): Generator<FixedSizeNodeData<ExtendedData> | string | symbol, void, boolean> {
const stack: StackElement[] = [];

stack.push({
Expand Down Expand Up @@ -94,9 +94,9 @@ function* treeWalker(
}
}

const Node: React.FunctionComponent<
FixedSizeNodeComponentProps<ExtendedData>
> = ({data: {isLeaf, name, nestingLevel}, isOpen, style, toggle}) => (
const Node: React.FunctionComponent<FixedSizeNodeComponentProps<
ExtendedData
>> = ({data: {isLeaf, name, nestingLevel}, isOpen, style, toggle}) => (
<div
style={{
...style,
Expand Down
16 changes: 9 additions & 7 deletions __stories__/VariableSizeTree.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ const rootNode = createNode();
const defaultGapStyle = {marginLeft: 10};
const defaultButtonStyle = {fontFamily: 'Courier New'};

const Node: React.FunctionComponent<
VariableSizeNodeComponentProps<ExtendedData>
> = ({
const Node: React.FunctionComponent<VariableSizeNodeComponentProps<
ExtendedData
>> = ({
height,
data: {isLeaf, name, nestingLevel},
isOpen,
Expand Down Expand Up @@ -116,7 +116,11 @@ const TreePresenter: React.FunctionComponent<TreePresenterProps> = ({
const treeWalker = React.useCallback(
function*(
refresh: boolean,
): IterableIterator<VariableSizeNodeData<ExtendedData> | string | symbol> {
): Generator<
VariableSizeNodeData<ExtendedData> | string | symbol,
void,
boolean
> {
const stack: StackElement[] = [];

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

React.useEffect(() => {
if (tree.current) {
tree.current!.recomputeTree({refreshNodes: true, useDefaultHeight: true});
}
tree.current?.recomputeTree({refreshNodes: true, useDefaultHeight: true});
}, [itemSize]);

return (
Expand Down
13 changes: 8 additions & 5 deletions __tests__/FixedSizeTree.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ type ExtendedData = {
};

describe('FixedSizeTree', () => {
const Node: React.FunctionComponent<
FixedSizeNodeComponentProps<ExtendedData>
> = () => null;
const Node: React.FunctionComponent<FixedSizeNodeComponentProps<
ExtendedData
>> = () => null;

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

beforeEach(() => {
tree = {
children: [{id: 'foo-2', name: 'Foo #2'}, {id: 'foo-3', name: 'Foo #3'}],
children: [
{id: 'foo-2', name: 'Foo #2'},
{id: 'foo-3', name: 'Foo #3'},
],
id: 'foo-1',
name: 'Foo #1',
};
Expand Down Expand Up @@ -196,7 +199,7 @@ describe('FixedSizeTree', () => {
name: 'Foo #1',
};

await treeInstance.recomputeTree({refreshNodes: false});
await treeInstance.recomputeTree();
component.update(); // update the wrapper to get the latest changes

expect(component.find(FixedSizeList).prop('itemData')).toMatchObject({
Expand Down
13 changes: 8 additions & 5 deletions __tests__/VariableSizeTree.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ type ExtendedData = {
};

describe('VariableSizeTree', () => {
const Node: React.FunctionComponent<
VariableSizeNodeComponentProps<ExtendedData>
> = () => null;
const Node: React.FunctionComponent<VariableSizeNodeComponentProps<
ExtendedData
>> = () => null;

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

beforeEach(() => {
tree = {
children: [{id: 'foo-2', name: 'Foo #2'}, {id: 'foo-3', name: 'Foo #3'}],
children: [
{id: 'foo-2', name: 'Foo #2'},
{id: 'foo-3', name: 'Foo #3'},
],
id: 'foo-1',
name: 'Foo #1',
};
Expand Down Expand Up @@ -212,7 +215,7 @@ describe('VariableSizeTree', () => {
name: 'Foo #1',
};

await treeInstance.recomputeTree({refreshNodes: false});
await treeInstance.recomputeTree();
component.update(); // update the wrapper to get the latest changes

expect(component.find(VariableSizeList).prop('itemData')).toMatchObject(
Expand Down
Loading