11import { Derived , Store , batch } from '@tanstack/store'
2+ import { throttle } from '@tanstack/pacer'
23import { v4 as uuidv4 } from 'uuid'
34import {
45 deleteBy ,
@@ -21,11 +22,6 @@ import {
2122} from './standardSchemaValidator'
2223import { defaultFieldMeta , metaHelper } from './metaHelper'
2324import { formEventClient } from './EventClient'
24- import type {
25- RequestFormForceReset ,
26- RequestFormReset ,
27- RequestFormState ,
28- } from './EventClient'
2925import type { ValidationLogicFn } from './ValidationLogic'
3026import type {
3127 StandardSchemaV1 ,
@@ -1296,17 +1292,26 @@ export class FormApi<
12961292
12971293 this . update ( opts || { } )
12981294
1295+ const debouncedDevtoolState = throttle (
1296+ ( state : AnyFormState ) =>
1297+ formEventClient . emit ( 'form-state' , {
1298+ id : this . _formId ,
1299+ state : state ,
1300+ } ) ,
1301+ {
1302+ wait : 300 ,
1303+ } ,
1304+ )
1305+
1306+ // devtool broadcasts
12991307 this . store . subscribe ( ( ) => {
1300- formEventClient . emit ( 'form-state-change' , {
1301- id : this . _formId ,
1302- state : this . store . state ,
1303- options : this . options ,
1304- } )
1308+ debouncedDevtoolState ( this . store . state )
13051309 } )
13061310
1311+ // devtool requests
13071312 formEventClient . on ( 'request-form-state' , ( e ) => {
13081313 if ( e . payload . id === this . _formId ) {
1309- formEventClient . emit ( 'form-state-change ' , {
1314+ formEventClient . emit ( 'form-api ' , {
13101315 id : this . _formId ,
13111316 state : this . store . state ,
13121317 options : this . options ,
@@ -1376,7 +1381,7 @@ export class FormApi<
13761381 const { onMount } = this . options . validators || { }
13771382
13781383 // broadcast form state for devtools on mounting
1379- formEventClient . emit ( 'form-state-change ' , {
1384+ formEventClient . emit ( 'form-api ' , {
13801385 id : this . _formId ,
13811386 state : this . store . state ,
13821387 options : this . options ,
@@ -1454,6 +1459,12 @@ export class FormApi<
14541459 ) ,
14551460 )
14561461 } )
1462+
1463+ formEventClient . emit ( 'form-api' , {
1464+ id : this . _formId ,
1465+ state : this . store . state ,
1466+ options : this . options ,
1467+ } )
14571468 }
14581469
14591470 /**
@@ -2035,7 +2046,7 @@ export class FormApi<
20352046 meta : submitMetaArg ,
20362047 } )
20372048
2038- formEventClient . emit ( 'form-submission-state-change ' , {
2049+ formEventClient . emit ( 'form-submission' , {
20392050 id : this . _formId ,
20402051 submissionAttempt : this . state . submissionAttempts ,
20412052 successful : false ,
@@ -2059,7 +2070,7 @@ export class FormApi<
20592070 meta : submitMetaArg ,
20602071 } )
20612072
2062- formEventClient . emit ( 'form-submission-state-change ' , {
2073+ formEventClient . emit ( 'form-submission' , {
20632074 id : this . _formId ,
20642075 submissionAttempt : this . state . submissionAttempts ,
20652076 successful : false ,
@@ -2098,7 +2109,7 @@ export class FormApi<
20982109 isSubmitSuccessful : true , // Set isSubmitSuccessful to true on successful submission
20992110 } ) )
21002111
2101- formEventClient . emit ( 'form-submission-state-change ' , {
2112+ formEventClient . emit ( 'form-submission' , {
21022113 id : this . _formId ,
21032114 submissionAttempt : this . state . submissionAttempts ,
21042115 successful : true ,
@@ -2112,7 +2123,7 @@ export class FormApi<
21122123 isSubmitSuccessful : false , // Ensure isSubmitSuccessful is false if an error occurs
21132124 } ) )
21142125
2115- formEventClient . emit ( 'form-submission-state-change ' , {
2126+ formEventClient . emit ( 'form-submission' , {
21162127 id : this . _formId ,
21172128 submissionAttempt : this . state . submissionAttempts ,
21182129 successful : false ,
0 commit comments