Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/sparkly-paths-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/form-core': patch
---

Bump TanStack pacer to pacer-lite for reduced custom event emissions.
2 changes: 1 addition & 1 deletion packages/form-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
],
"dependencies": {
"@tanstack/devtools-event-client": "^0.3.5",
"@tanstack/pacer": "^0.15.3",
"@tanstack/pacer-lite": "^0.1.0",
"@tanstack/store": "^0.7.7"
},
"devDependencies": {
Expand Down
18 changes: 4 additions & 14 deletions packages/form-core/src/FormApi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Derived, Store, batch } from '@tanstack/store'
import { throttle } from '@tanstack/pacer'
import {
deleteBy,
determineFormLevelErrorSourceAndValue,
Expand All @@ -15,13 +14,15 @@ import {
uuid,
} from './utils'
import { defaultValidationLogic } from './ValidationLogic'

import {
isStandardSchemaValidator,
standardSchemaValidators,
} from './standardSchemaValidator'
import { defaultFieldMeta, metaHelper } from './metaHelper'
import { formEventClient } from './EventClient'
import { throttleFormState } from './throttles'

// types
import type { ValidationLogicFn } from './ValidationLogic'
import type {
StandardSchemaV1,
Expand Down Expand Up @@ -1304,20 +1305,9 @@ export class FormApi<

this.update(opts || {})

const debouncedDevtoolState = throttle(
(state: AnyFormState) =>
formEventClient.emit('form-state', {
id: this._formId,
state: state,
}),
{
wait: 300,
},
)

// devtool broadcasts
this.store.subscribe(() => {
debouncedDevtoolState(this.store.state)
throttleFormState(this)
})

// devtool requests
Expand Down
15 changes: 15 additions & 0 deletions packages/form-core/src/throttles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { liteThrottle } from '@tanstack/pacer-lite'
import { formEventClient } from './EventClient'

import type { AnyFormApi } from './FormApi'

export const throttleFormState = liteThrottle(
(form: AnyFormApi) =>
formEventClient.emit('form-state', {
id: form.formId,
state: form.store.state,
}),
{
wait: 300,
},
)
1 change: 0 additions & 1 deletion packages/form-core/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { defaultValidationLogic } from './ValidationLogic'
import type { ValidationLogicProps } from './ValidationLogic'
import type { FieldValidators } from './FieldApi'
import type { FormValidators } from './FormApi'
Expand Down
Loading
Loading