Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export Type declarations for turbo: events #452

Merged
merged 1 commit into from Jul 15, 2022

Conversation

seanpdoyle
Copy link
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
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.

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
Member

dhh commented Jun 19, 2022

Want to rebase this @seanpdoyle?

@dhh
Copy link
Member

dhh commented Jul 15, 2022

Seems like a legit test failure.

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
@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 added 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.

None yet

3 participants