Skip to content
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

Morph stimulus reflex element AKA "single element page morph" #522

Merged

Conversation

julianrubisch
Copy link
Contributor

Feature

Description

This PR allows to morph over the StimulusReflex::Element that initiated the reflex, like so:

morph element, render(MyComponent.new(...))

This is especially handy when

  1. replacing a single partial or ViewComponent, without having to look up the ID
  2. when calling this.stimulate with a dedicated element as a target

Why should this be added

Often, when performing a selector morph, one is altering the state of a single piece of the UI and patching it. This PR allows to do so without explicitly stating a selector or AR model/relation,

❗ Attention

depends on stimulusreflex/cable_ready#135

Checklist

  • My code follows the style guidelines of this project
  • Checks (StandardRB & Prettier-Standard) are passing
  • This is not a documentation update

Please note that the best way to suggest changes or updates to the documentation is to join Discord and leave a note in the #docs channel. Any documentation updates posted as PRs cannot be accepted at this time. ❤️

@julianrubisch julianrubisch added proposal ruby Pull requests that update Ruby code labels Jun 24, 2021
@julianrubisch
Copy link
Contributor Author

Failing tests are also because of the dependency on cableready/master

Copy link
Contributor

@leastbad leastbad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a suggestion to memoize update.selector if reasonable.

I did my best to trace the logic of your refactoring; it looks good but to offer you advice I frequently don't take myself: it's easier to click Approve if you keep refactoring and feature implementation in separate PRs. 😉

lib/stimulus_reflex/broadcasters/selector_broadcaster.rb Outdated Show resolved Hide resolved
lib/stimulus_reflex/broadcasters/selector_broadcaster.rb Outdated Show resolved Hide resolved
lib/stimulus_reflex/broadcasters/selector_broadcaster.rb Outdated Show resolved Hide resolved
lib/stimulus_reflex/element.rb Show resolved Hide resolved
@julianrubisch
Copy link
Contributor Author

Re splitting: yes, but at the cost at producing merge conflicts 😜

@julianrubisch
Copy link
Contributor Author

All done!

@leastbad
Copy link
Contributor

LGTM!

@leastbad leastbad merged commit 4c52f31 into stimulusreflex:master Jul 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal ruby Pull requests that update Ruby code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants