Add dom_target helper to create dom_id-like strings from an unlimited number of objects - #55204
Merged
Conversation
dom_target helper to create dom_id-like strings from an unlim…dom_target helper to create dom_id-like strings from an unlimited number of objects
Contributor
Author
|
I can fix up the changelog. I want to change one behavior I noticed that I want to fix before it's baked: dom_target(User) #=> "user"
dom_target(User.new) #=> "new_user"Edit: ✅ |
Member
|
I did a small change to use a |
…ited number of objects
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation / Background
This Pull Request has been created because it's increasingly necessary to create complex DOM identifiers and the existing
dom_idis limited.This PR creates a new method
ActionView::RecordIdentifier#dom_targetthat can create a unique identifier from an unlimited number of objects, which differentiates it fromdom_idwhich only takes a single object and an optional string prefix.I chose the name of
targetbecause I found myself wanting this for generatingturbo-railsTurbo Broadcast targets.dom_targetis inspired by the structure ofturbo_stream_from(*streamables), which concatenates an unlimited number of objects into a single identifier.Adding an new helper method is proposed as an alternative to adding new behavior to existing
dom_idordom_classhelper methods, which had questions/objections. Related:dom_idanddom_classto accept var-args #44081Additional information
Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]