Make Renderer
instance available to View
delegates
#1027
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The changes proposed in #1019 require dispatching the new
Renderer.renderMethod
property as part of theturbo:render
event. Similarly, there's an opportunity to include that information in theturbo:before-render
,turbo:before-frame-render
, andturbo:frame-render
events.To simplify those chains of object access, this commit changes the
View
class delegate'sallowsImmediateRender
andviewRenderedSnapshot
methods to accept theRenderer
instance, instead of individual properties.With access to the instance, the delegate's can read properties like
isPreview
along with theelement
(transitively through thenewSnapshot
property).In order to dispatch the
turbo:frame-render
event closer to the moment in time that the view renders, this commit removes theSession.frameRendered
callback, and replaces it with adispatch("turbo:frame-render")
call inside theFrameController.viewRenderedSnapshot(renderer)
delegate method.In order to do so, this commit must work around the fact that
turbo:frame-render
events include theFetchResponse
instance involved in the render. Since that instance isn't available at render time, this commit wraps theawait this.view.render(renderer)
in a utility function that injects theFetchResponse
instance into the Custom event'sevent.detail
object immediately after it's initially dispatched.Ideally, this work around will only be temporary, since the
turbo:frame-load
event also includesevent.detail.fetchResponse
. There's an opportunity to deprecate that property inturbo:frame-render
events in the future.