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

configure operations for morph and replace #599

Merged
merged 1 commit into from
Jul 29, 2022
Merged

Conversation

leastbad
Copy link
Contributor

@leastbad leastbad commented Jul 29, 2022

Type of PR (feature, enhancement, bug fix, etc.)

Feature

Description

Allow overriding the default CableReady operations used by page and selector morphs via the initializer. By default, these values are:

config.morph_operation = :morph
config.replace_operation = :inner_html

The actual options passed to these operations is unchanged; it's up to the developer to implement a custom CableReady operation that handles the data coming from the server.

If you are using this feature, be sure to be aware of the options being sent to the client by the page broadcaster, as well as the selector broadcaster morph and replace mechanisms.

For reference, here is the existing CableReady morph and inner_html operations, which could serve as a starting point.

Why should this be added

  1. People might want to use the Alpine morph method. @marcoroth has created https://github.com/cableready/alpine_morph just for you!
  2. People might want to clone the morph method but change it so that children_only: false. Note that this will likely interfere with normal SR operations, so consider it a sharp knife.

Checklist

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

@leastbad leastbad added this to the 3.5 milestone Jul 29, 2022
@leastbad leastbad requested a review from marcoroth July 29, 2022 20:00
@leastbad leastbad self-assigned this Jul 29, 2022
@marcoroth
Copy link
Member

marcoroth commented Jul 29, 2022

I think this looks good!

We might even be able to automatically register the operations names if they weren't registered yet - So it's even easier to use.

Sort of calling this if the operation is not already present:

CableReady.configure do |config|
  config.add_operation_name(StimulusReflex.config.morph_operation)
end

@leastbad
Copy link
Contributor Author

Perhaps! I figure that this could backfire because it just creates more stuff you have to know for very little real benefit, since you still have to declare all of the other custom operations that you define.

@leastbad leastbad merged commit f9147a7 into master Jul 29, 2022
@leastbad leastbad deleted the configurable_operations branch July 29, 2022 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants