@@ -186,7 +186,12 @@ class Tests extends React.Component<DevToolProps, State> {
186186 * Every setState call will have to go through this, otherwise we get race conditions
187187 * where the underlying state has changed, but the draftState didn't change.
188188 */
189- setStateDebounced = ( setStateFunc , time = 200 ) => {
189+ setStateDelayedFlush = (
190+ setStateFunc :
191+ | Partial < State >
192+ | ( ( state : State , props : DevToolProps ) => Partial < State > ) ,
193+ time = 200
194+ ) => {
190195 const draftState = this . draftState || this . state ;
191196
192197 const newState =
@@ -217,7 +222,7 @@ class Tests extends React.Component<DevToolProps, State> {
217222
218223 UNSAFE_componentWillReceiveProps ( nextProps : DevToolProps ) {
219224 if ( nextProps . sandboxId !== this . props . sandboxId ) {
220- this . setStateDebounced (
225+ this . setStateDelayedFlush (
221226 {
222227 files : { } ,
223228 selectedFilePath : null ,
@@ -233,7 +238,7 @@ class Tests extends React.Component<DevToolProps, State> {
233238 }
234239
235240 selectFile = ( file : File ) => {
236- this . setStateDebounced (
241+ this . setStateDelayedFlush (
237242 state => ( {
238243 selectedFilePath :
239244 file . fileName === state . selectedFilePath ? null : file . fileName ,
@@ -243,7 +248,7 @@ class Tests extends React.Component<DevToolProps, State> {
243248 } ;
244249
245250 toggleFileExpansion = ( file : File ) => {
246- this . setStateDebounced (
251+ this . setStateDelayedFlush (
247252 oldState =>
248253 immer ( oldState , state => {
249254 state . fileExpansionState [ file . fileName ] = ! state . fileExpansionState [
@@ -278,7 +283,7 @@ class Tests extends React.Component<DevToolProps, State> {
278283 if ( this . props . updateStatus ) {
279284 this . props . updateStatus ( 'clear' ) ;
280285 }
281- this . setStateDebounced ( INITIAL_STATE , 0 ) ;
286+ this . setStateDelayedFlush ( INITIAL_STATE , 0 ) ;
282287 break ;
283288 }
284289 case 'test_count' : {
@@ -294,7 +299,7 @@ class Tests extends React.Component<DevToolProps, State> {
294299 if ( this . props . updateStatus ) {
295300 this . props . updateStatus ( 'clear' ) ;
296301 }
297- this . setStateDebounced (
302+ this . setStateDelayedFlush (
298303 {
299304 running : true ,
300305 } ,
@@ -303,7 +308,7 @@ class Tests extends React.Component<DevToolProps, State> {
303308 break ;
304309 }
305310 case messages . TOTAL_TEST_END : {
306- this . setStateDebounced (
311+ this . setStateDelayedFlush (
307312 {
308313 running : false ,
309314 } ,
@@ -333,7 +338,7 @@ class Tests extends React.Component<DevToolProps, State> {
333338 }
334339
335340 case messages . ADD_FILE : {
336- this . setStateDebounced ( oldState =>
341+ this . setStateDelayedFlush ( oldState =>
337342 immer ( oldState , state => {
338343 state . files [ data . path ] = {
339344 tests : { } ,
@@ -346,7 +351,7 @@ class Tests extends React.Component<DevToolProps, State> {
346351 break ;
347352 }
348353 case 'remove_file' : {
349- this . setStateDebounced ( oldState =>
354+ this . setStateDelayedFlush ( oldState =>
350355 immer ( oldState , state => {
351356 if ( state . files [ data . path ] ) {
352357 delete state . files [ data . path ] ;
@@ -358,7 +363,7 @@ class Tests extends React.Component<DevToolProps, State> {
358363 break ;
359364 }
360365 case messages . FILE_ERROR : {
361- this . setStateDebounced ( oldState =>
366+ this . setStateDelayedFlush ( oldState =>
362367 immer ( oldState , state => {
363368 if ( state . files [ data . path ] ) {
364369 state . files [ data . path ] . fileError = data . error ;
@@ -378,7 +383,7 @@ class Tests extends React.Component<DevToolProps, State> {
378383 case messages . ADD_TEST : {
379384 const testName = [ ...this . currentDescribeBlocks , data . testName ] ;
380385
381- this . setStateDebounced ( oldState =>
386+ this . setStateDelayedFlush ( oldState =>
382387 immer ( oldState , state => {
383388 if ( ! state . files [ data . path ] ) {
384389 state . files [ data . path ] = {
@@ -404,7 +409,7 @@ class Tests extends React.Component<DevToolProps, State> {
404409 const { test } = data ;
405410 const testName = [ ...test . blocks , test . name ] ;
406411
407- this . setStateDebounced ( oldState =>
412+ this . setStateDelayedFlush ( oldState =>
408413 immer ( oldState , state => {
409414 if ( ! state . files [ test . path ] ) {
410415 state . files [ test . path ] = {
@@ -435,7 +440,7 @@ class Tests extends React.Component<DevToolProps, State> {
435440 const { test } = data ;
436441 const testName = [ ...test . blocks , test . name ] ;
437442
438- this . setStateDebounced ( oldState =>
443+ this . setStateDelayedFlush ( oldState =>
439444 immer ( oldState , state => {
440445 if ( ! state . files [ test . path ] ) {
441446 return ;
@@ -524,22 +529,22 @@ class Tests extends React.Component<DevToolProps, State> {
524529 } ;
525530
526531 toggleWatching = ( ) => {
527- this . setStateDebounced ( state => ( { watching : ! state . watching } ) , 0 ) ;
532+ this . setStateDelayedFlush ( state => ( { watching : ! state . watching } ) , 0 ) ;
528533 dispatch ( {
529534 type : 'set-test-watching' ,
530535 watching : ! this . state . watching ,
531536 } ) ;
532537 } ;
533538
534539 runAllTests = ( ) => {
535- this . setStateDebounced ( { files : { } } , 0 ) ;
540+ this . setStateDelayedFlush ( { files : { } } , 0 ) ;
536541 dispatch ( {
537542 type : 'run-all-tests' ,
538543 } ) ;
539544 } ;
540545
541546 runTests = ( file : File ) => {
542- this . setStateDebounced (
547+ this . setStateDelayedFlush (
543548 oldState =>
544549 immer ( oldState , state => {
545550 if ( state . files [ file . fileName ] ) {
0 commit comments