Let developers associate lifecycle events #764
Draft
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.
Currently there is no way to know which events are tied to a given user action. For example, it's not possible to associate a
turbo:click
with aturbo:visit
. One might link aturbo:click
with the nextturbo:visit
, but this isn't accurate because a navigation can be ended by cancellingturbo:click
orturbo:before-visit
(as mentioned by @pfeiffer in #99 (comment)).With a lifecycle ID present in each event, it'll be possible to reference the initiator element, providing a way for developers to customise visit behaviour based on HTML attributes. For example:
It could also be used to determine redirect visits, as
turbo:visit
is dispatched twice with the same lifecycle ID:This is a lower-level alternative to #750, and whilst I still think that the type annotations in that PR are worthwhile, this might provide some useful information for other cases without having to manipulate
VisitOptions
too much.If we think this approach is worth pursuing, I can finish it up by adding identifiers to the remaining events.
Todo: