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
2 changes: 1 addition & 1 deletion packages/form-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"src"
],
"dependencies": {
"@tanstack/devtools-event-client": "^0.3.5",
"@tanstack/devtools-event-client": "^0.4.0",
"@tanstack/pacer-lite": "^0.1.1",
"@tanstack/store": "^0.7.7"
},
Expand Down
74 changes: 44 additions & 30 deletions packages/form-core/src/FormApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1310,36 +1310,6 @@ export class FormApi<
this.handleSubmit = this.handleSubmit.bind(this)

this.update(opts || {})

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

// devtool requests
formEventClient.on('request-form-state', (e) => {
if (e.payload.id === this._formId) {
formEventClient.emit('form-api', {
id: this._formId,
state: this.store.state,
options: this.options,
})
}
})

formEventClient.on('request-form-reset', (e) => {
if (e.payload.id === this._formId) {
this.reset()
}
})

formEventClient.on('request-form-force-submit', (e) => {
if (e.payload.id === this._formId) {
this._devtoolsSubmissionOverride = true
this.handleSubmit()
this._devtoolsSubmissionOverride = false
}
})
}

get formId(): string {
Expand Down Expand Up @@ -1374,7 +1344,51 @@ export class FormApi<
mount = () => {
const cleanupFieldMetaDerived = this.fieldMetaDerived.mount()
const cleanupStoreDerived = this.store.mount()

// devtool broadcasts
const cleanupDevtoolBroadcast = this.store.subscribe(() => {
throttleFormState(this)
})

// devtool requests
const cleanupFormStateListener = formEventClient.on(
'request-form-state',
(e) => {
if (e.payload.id === this._formId) {
formEventClient.emit('form-api', {
id: this._formId,
state: this.store.state,
options: this.options,
})
}
},
)

const cleanupFormResetListener = formEventClient.on(
'request-form-reset',
(e) => {
if (e.payload.id === this._formId) {
this.reset()
}
},
)

const cleanupFormForceSubmitListener = formEventClient.on(
'request-form-force-submit',
(e) => {
if (e.payload.id === this._formId) {
this._devtoolsSubmissionOverride = true
this.handleSubmit()
this._devtoolsSubmissionOverride = false
}
},
)

const cleanup = () => {
cleanupFormForceSubmitListener()
cleanupFormResetListener()
cleanupFormStateListener()
cleanupDevtoolBroadcast()
cleanupFieldMetaDerived()
cleanupStoreDerived()

Expand Down
Loading
Loading