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

Extract DriveDelegate interface #657

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

seanpdoyle
Copy link
Contributor

@seanpdoyle seanpdoyle commented Jul 30, 2022

The FrameController depends on the application's singleton Session
instance in several ways:

  • it drives the History
  • it determines whether or not an Element is "enabled" to navigate a
    page or frame
  • it preloads links
  • it dispatches turbo:frame-render and turbo:frame-load events
  • it can initiate a Visit

This commit codifies those dependent behaviors by creating the
DriveDelegate interface and declaring the Session class as an
extension of that interface.

With the codification of the DriveDelegate responsibilities
established, managing turbo:frame-render and turbo:frame-load events
feels out of scope. To resolve that, this commit migrates the
Session.frameRendered and Session.frameLoaded methods to the
FrameController, and omits them from the DriveDelegate interface.

The FrameController still directly imports the singleton instance of
the Session from the src/core/index module, but assigns it to a
delegate: DriveDelegate property for use throughout the class.

The next step would be to find a way to forward the session instance
into the FrameElement.delegateConstructor assignment.

Copy link
Member

@marcoroth marcoroth left a comment

Choose a reason for hiding this comment

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

I really appreciate the work being done here, this is a really good extraction and refactoring!

I just have one question: what was your thought around having frameMissingFromResponse() as part of the DriveDelegate interface?

Why would other potential classes (that have a DriveDelegate) care about dispatching a warning about missing frames? Isn't that the sole responsibility of the FrameController?

@seanpdoyle seanpdoyle force-pushed the drive-delegate branch 2 times, most recently from e95ad6b to 680b662 Compare September 7, 2022 13:01
@seanpdoyle
Copy link
Contributor Author

@marcoroth these changes were proposed in the early stages of missing frame handling. I've rebased and moved all frame-related checks to the FrameController.

Copy link
Member

@marcoroth marcoroth left a comment

Choose a reason for hiding this comment

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

Ah, that would explain it!

This looks good from my side! 🥳

@seanpdoyle
Copy link
Contributor Author

@manuelpuyol @kevinmcconnell I'd really appreciate a review of this changeset, if you're able to provide some.

The `FrameController` depends on the application's singleton `Session`
instance in several ways:

* it drives the `History`
* it determines whether or not an `Element` is "enabled" to navigate a
  page or frame
* it preloads links
* it dispatches `turbo:frame-render` and `turbo:frame-load` events
* it can initiate a `Visit`

This commit codifies those dependent behaviors by creating the
`DriveDelegate` interface and declaring the `Session` class as an
extension of that interface.

With the codification of the `DriveDelegate` responsibilities
established, managing `turbo:frame-render` and `turbo:frame-load` events
feels out of scope. To resolve that, this commit migrates the
`Session.frameRendered` and `Session.frameLoaded` methods to the
`FrameController`, and omits them from the `DriveDelegate` interface.

The `FrameController` still directly imports the singleton instance of
the `Session` from the `src/core/index` module, but assigns it to a
`delegate: DriveDelegate` property for use throughout the class.

The next step would be to find a way to forward the `session` instance
into the [FrameElement.delegateConstructor][] assignment.

[FrameElement.delegateConstructor]: https://github.com/hotwired/turbo/blob/3a18111412cb4190b818b96c9c6aad7264cc4441/src/elements/index.ts#L6
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