Skip to content

Commit

Permalink
Merge pull request #63 from shiftyp/type-improvement-1
Browse files Browse the repository at this point in the history
Typed events
  • Loading branch information
shiftyp authored Sep 17, 2023
2 parents 811f22b + 3ca3541 commit 2591d2d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/core/drive/form_submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<FormSubmission["result"], undefined>>

export interface FormSubmissionDelegate {
formSubmissionStarted(formSubmission: FormSubmission): void
formSubmissionSucceededWithResponse(formSubmission: FormSubmission, fetchResponse: FetchResponse): void
Expand Down Expand Up @@ -145,7 +153,7 @@ export class FormSubmission {
this.state = FormSubmissionState.waiting
this.submitter?.setAttribute("disabled", "")
this.setSubmitsWith()
dispatch("turbo:submit-start", {
dispatch<TurboSubmitStartEvent>("turbo:submit-start", {
target: this.formElement,
detail: { formSubmission: this },
})
Expand Down Expand Up @@ -183,7 +191,7 @@ export class FormSubmission {
this.state = FormSubmissionState.stopped
this.submitter?.removeAttribute("disabled")
this.resetSubmitterText()
dispatch("turbo:submit-end", {
dispatch<TurboSubmitEndEvent>("turbo:submit-end", {
target: this.formElement,
detail: { formSubmission: this, ...this.result },
})
Expand Down
2 changes: 1 addition & 1 deletion src/core/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReloadReason>
export type TurboBeforeFrameRenderEvent = CustomEvent<{ newFrame: FrameElement } & FrameViewRenderOptions>
export type TurboFrameRenderEvent = CustomEvent<{ fetchResponse: FetchResponse }>
export type TurboLoadEvent = CustomEvent<{ url: string; timing: TimingData }>
Expand Down

0 comments on commit 2591d2d

Please sign in to comment.