Skip to content

Export Type declarations for turbo: events#452

Merged
dhh merged 1 commit intohotwired:mainfrom
seanpdoyle:publish-event-types
Jul 15, 2022
Merged

Export Type declarations for turbo: events#452
dhh merged 1 commit intohotwired:mainfrom
seanpdoyle:publish-event-types

Conversation

@seanpdoyle
Copy link
Copy Markdown
Contributor

Various turbo:-prefixed events are dispatched as CustomEvent
instances with data encoded into the detail property.

In TypeScript, that property is encoded as any, but the CustomEvent
type is generic (i.e. CustomEvent<T>) where the generic Type argument
describes the structure of the detail key.

This commit introduces types that extend from CustomEvent for each
event, and exports them from /core/index.ts, which is exported from
/index.ts in-turn.

In practice, there are no changes to the implementation. However,
TypeScript consumers of the package can import the types. At the same
time, the internal implementation can depend on the types to ensure
consistency throughout.

TurboBeforeCacheEvent,
TurboBeforeRenderEvent,
TurboBeforeVisitEvent,
TurboClickEvent,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what would be better: BeforeCacheEvent, BeforeRenderEvent, etc internally and exporting them here as Turbo-prefixed versions, or sticking with the current style of qualifying them with Turbo.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or even export them without the Turbo prefix? FrameElement and StreamElement don't have it.

@seanpdoyle seanpdoyle force-pushed the publish-event-types branch 2 times, most recently from 6c9b740 to df3ad64 Compare November 20, 2021 02:45
@seanpdoyle seanpdoyle force-pushed the publish-event-types branch 5 times, most recently from 13ef36d to b1a5b44 Compare April 1, 2022 15:41
@dhh
Copy link
Copy Markdown
Member

dhh commented Jun 19, 2022

Want to rebase this @seanpdoyle?

@seanpdoyle seanpdoyle force-pushed the publish-event-types branch 3 times, most recently from b9bfd7f to 17bf33c Compare June 19, 2022 14:27
@dhh
Copy link
Copy Markdown
Member

dhh commented Jul 15, 2022

Seems like a legit test failure.

@seanpdoyle seanpdoyle force-pushed the publish-event-types branch from 3ec5201 to be23945 Compare July 15, 2022 23:39
Various `turbo:`-prefixed events are dispatched as [CustomEvent][]
instances with data encoded into the [detail][] property.

In TypeScript, that property is encoded as `any`, but the `CustomEvent`
type is generic (i.e. `CustomEvent<T>`) where the generic Type argument
describes the structure of the `detail` key.

This commit introduces types that extend from `CustomEvent` for each
event, and exports them from `/core/index.ts`, which is exported from
`/index.ts` in-turn.

In practice, there are no changes to the implementation. However,
TypeScript consumers of the package can import the types. At the same
time, the internal implementation can depend on the types to ensure
consistency throughout.

[CustomEvent]: https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent
[detail]: https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/detail
@seanpdoyle seanpdoyle force-pushed the publish-event-types branch from be23945 to 734a7a8 Compare July 15, 2022 23:43
@dhh dhh merged commit 2d5cdda into hotwired:main Jul 15, 2022
@seanpdoyle seanpdoyle deleted the publish-event-types branch July 16, 2022 00:09
dhh pushed a commit to feliperaul/turbo that referenced this pull request Jul 16, 2022
* main:
  Allow frames to scroll smoothly into view (hotwired#607)
  Export Type declarations for `turbo:` events (hotwired#452)
  Add .php as a valid isHTML extension (hotwired#629)
  Add original click event to 'turbo:click' details (hotwired#611)
  Drive Browser tests with `playwright` (hotwired#609)
  Allow Turbo Streams w/ GET via `data-turbo-stream` (hotwired#612)
  Only update history when Turbo visit is renderable (hotwired#601)
  Support development ChromeDriver version overrides (hotwired#606)
  Turbo stream source (hotwired#415)
  Expose Frame load state via `[complete]` attribute (hotwired#487)
  fix(ie/edge): form.method='delete', raises Invalid argument. (hotwired#586)
  Do not declare global types/constants (hotwired#524)
  Defensively create custom turbo elements (hotwired#483)
  Use `replaceChildren` in StreamActions.update (hotwired#534)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants