-
-
Notifications
You must be signed in to change notification settings - Fork 172
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
implicit dom_id for morph selectors #436
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if there is any additional syntactic sugar we could include by leveraging to_partial_path. Too magical?
I think that we're implicitly leveraging What do you have in mind? Tell me like I'm not in your head! 🤓 |
I reworked the new Either way, I had to allow the All of this is open to iteration. 💯 |
Type of PR (feature, enhancement, bug fix, etc.)
Enhancement
Description
This proposes to allow
morph
to accept a resource in lieu of a CSS selector. Any resource will be converted to a string withdom_id
.Before:
After:
Before:
After:
I've also made the
Reflex#dom_id
helper more powerful than its Rails counterpart, so that it now accepts ActiveRecord relations and arbitrary objects (that get converted to strings):That's all pretty cool, but with the above in place, we can dial it up.
This is equivalent to:
And, thanks to a quirk in the way that morphdom works, this is now possible:
This is equivalent to:
morphdom DGAF so long as the outermost container element has the same
id
as the target. If you happen to be rendering a collection with a partial that lines up with render defaults, we can now infer everything but the collection itself.Finally, I added a
render_collection
method toReflex
that developers can use for more complex morphs:Thanks to @RolandStuder for the initial inspiration.
Why should this be added
Developer happiness and the principle of least surprise.
Checklist