From 3ca3541688ec7c9a9ff99480d68b9b96386620d9 Mon Sep 17 00:00:00 2001 From: Ryan Lynch Date: Sun, 17 Sep 2023 10:06:52 -0400 Subject: [PATCH] Typed events --- src/core/drive/form_submission.ts | 12 ++++++++++-- src/core/session.ts | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/core/drive/form_submission.ts b/src/core/drive/form_submission.ts index 5d497ba23..6ba1ed2e3 100644 --- a/src/core/drive/form_submission.ts +++ b/src/core/drive/form_submission.ts @@ -10,6 +10,14 @@ import { dispatch, getAttribute, getMetaContent, hasAttribute } from "../../util import { StreamMessage } from "../streams/stream_message" import { FetchResponse } from "../../http/fetch_response" +export type TurboSubmitStartEvent = CustomEvent<{ + formSubmission: FormSubmission +}> + +export type TurboSubmitEndEvent = CustomEvent<{ + formSubmission: FormSubmission, +} & Exclude> + export interface FormSubmissionDelegate { formSubmissionStarted(formSubmission: FormSubmission): void formSubmissionSucceededWithResponse(formSubmission: FormSubmission, fetchResponse: FetchResponse): void @@ -145,7 +153,7 @@ export class FormSubmission { this.state = FormSubmissionState.waiting this.submitter?.setAttribute("disabled", "") this.setSubmitsWith() - dispatch("turbo:submit-start", { + dispatch("turbo:submit-start", { target: this.formElement, detail: { formSubmission: this }, }) @@ -183,7 +191,7 @@ export class FormSubmission { this.state = FormSubmissionState.stopped this.submitter?.removeAttribute("disabled") this.resetSubmitterText() - dispatch("turbo:submit-end", { + dispatch("turbo:submit-end", { target: this.formElement, detail: { formSubmission: this, ...this.result }, }) diff --git a/src/core/session.ts b/src/core/session.ts index 5ca13ad41..55df1cc0e 100644 --- a/src/core/session.ts +++ b/src/core/session.ts @@ -31,7 +31,7 @@ export type TurboBeforeRenderEvent = CustomEvent< > export type TurboBeforeVisitEvent = CustomEvent<{ url: string }> export type TurboClickEvent = CustomEvent<{ url: string; originalEvent: MouseEvent }> -export type TurboFrameLoadEvent = CustomEvent +export type TurboFrameLoadEvent = CustomEvent export type TurboBeforeFrameRenderEvent = CustomEvent<{ newFrame: FrameElement } & FrameViewRenderOptions> export type TurboFrameRenderEvent = CustomEvent<{ fetchResponse: FetchResponse }> export type TurboLoadEvent = CustomEvent<{ url: string; timing: TimingData }>