11import { number , withKnobs } from '@storybook/addon-knobs' ;
22import { storiesOf } from '@storybook/react' ;
3- import * as React from 'react' ;
3+ import React , { FC } from 'react' ;
44import AutoSizer from 'react-virtualized-auto-sizer' ;
5- import Tree , {
5+ import {
66 VariableSizeNodeComponentProps ,
77 VariableSizeNodeData ,
8- } from '../src/VariableSizeTree' ;
8+ VariableSizeTree ,
9+ } from '../src' ;
910
1011document . body . style . margin = '0' ;
1112document . body . style . display = 'flex' ;
@@ -15,22 +16,23 @@ const root = document.getElementById('root')!;
1516root . style . margin = '10px 0 0 10px' ;
1617root . style . flex = '1' ;
1718
18- type DataNode = {
19+ type DataNode = Readonly < {
1920 children : DataNode [ ] ;
2021 id : number ;
2122 name : string ;
22- } ;
23+ } > ;
2324
24- type StackElement = {
25+ type StackElement = Readonly < {
2526 nestingLevel : number ;
2627 node : DataNode ;
27- } ;
28+ } > ;
2829
29- type ExtendedData = {
30- readonly isLeaf : boolean ;
31- readonly name : string ;
32- readonly nestingLevel : number ;
33- } ;
30+ type ExtendedData = VariableSizeNodeData &
31+ Readonly < {
32+ isLeaf : boolean ;
33+ name : string ;
34+ nestingLevel : number ;
35+ } > ;
3436
3537let nodeId = 0 ;
3638
@@ -47,7 +49,6 @@ const createNode = (depth: number = 0) => {
4749 return node ;
4850 }
4951
50- // tslint:disable-next-line:increment-decrement
5152 for ( let i = 0 ; i < 5 ; i ++ ) {
5253 node . children . push ( createNode ( depth + 1 ) ) ;
5354 }
@@ -59,9 +60,7 @@ const rootNode = createNode();
5960const defaultGapStyle = { marginLeft : 10 } ;
6061const defaultButtonStyle = { fontFamily : 'Courier New' } ;
6162
62- const Node : React . FunctionComponent < VariableSizeNodeComponentProps <
63- ExtendedData
64- > > = ( {
63+ const Node : FC < VariableSizeNodeComponentProps < ExtendedData > > = ( {
6564 height,
6665 data : { isLeaf, name, nestingLevel} ,
6766 isOpen,
@@ -105,23 +104,19 @@ const Node: React.FunctionComponent<VariableSizeNodeComponentProps<
105104 ) ;
106105} ;
107106
108- interface TreePresenterProps {
107+ type TreePresenterProps = Readonly < {
109108 itemSize : number ;
110- }
109+ } > ;
111110
112111const TreePresenter : React . FunctionComponent < TreePresenterProps > = ( {
113112 itemSize,
114113} ) => {
115- const tree = React . useRef < Tree < ExtendedData > > ( null ) ;
114+ const tree = React . useRef < VariableSizeTree < ExtendedData > > ( null ) ;
116115
117116 const treeWalker = React . useCallback (
118- function * (
117+ function * treeWalker (
119118 refresh : boolean ,
120- ) : Generator <
121- VariableSizeNodeData < ExtendedData > | string | symbol ,
122- void ,
123- boolean
124- > {
119+ ) : Generator < ExtendedData | string | symbol , void , boolean > {
125120 const stack : StackElement [ ] = [ ] ;
126121
127122 stack . push ( {
@@ -145,7 +140,6 @@ const TreePresenter: React.FunctionComponent<TreePresenterProps> = ({
145140 : id ;
146141
147142 if ( node . children . length !== 0 && isOpened ) {
148- // tslint:disable-next-line:increment-decrement
149143 for ( let i = node . children . length - 1 ; i >= 0 ; i -- ) {
150144 stack . push ( {
151145 nestingLevel : nestingLevel + 1 ,
@@ -159,21 +153,25 @@ const TreePresenter: React.FunctionComponent<TreePresenterProps> = ({
159153 ) ;
160154
161155 React . useEffect ( ( ) => {
162- tree . current ?. recomputeTree ( { refreshNodes : true , useDefaultHeight : true } ) ;
156+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
157+ tree . current ?. recomputeTree ( {
158+ refreshNodes : true ,
159+ useDefaultHeight : true ,
160+ } ) ;
163161 } , [ itemSize ] ) ;
164162
165163 return (
166164 < AutoSizer disableWidth >
167165 { ( { height} ) => (
168- < Tree < ExtendedData >
166+ < VariableSizeTree
169167 ref = { tree }
170168 itemData = { itemSize }
171169 treeWalker = { treeWalker }
172170 height = { height }
173171 width = "100%"
174172 >
175173 { Node }
176- </ Tree >
174+ </ VariableSizeTree >
177175 ) }
178176 </ AutoSizer >
179177 ) ;
0 commit comments