You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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):
dom_id(post1)# "#post_1" (the current behaviour)dom_id(Post.all)# "#posts"dom_id("teapots","search")# "#teapots_search"
That's all pretty cool, but with the above in place, we can dial it up.
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 to Reflex that developers can use for more complex morphs:
I think that we're implicitly leveraging to_partial_path when we support the morph @posts syntax, even though it's not something we have to do directly.
What do you have in mind? Tell me like I'm not in your head! 🤓
I reworked the new dom_id method so that it was a case structure, but standardrb kicked my ass and turned it into an if/elsif and I'm no longer sure it's still cute.
Either way, I had to allow the wrap method to squash the # being prepended to prevent a dreaded double-hash. I also added a sub to the fall-through dom_id case to prevent people from accidentally sending an extra # character into the method.
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
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.
Type of PR (feature, enhancement, bug fix, etc.)
Enhancement
Description
This proposes to allow
morphto 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_idhelper 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
idas 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_collectionmethod toReflexthat 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