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

Rework CableReady's ActionController::Renderers #260

Merged
merged 5 commits into from
Mar 10, 2023

Conversation

marcoroth
Copy link
Member

@marcoroth marcoroth commented Mar 1, 2023

Type of PR

Deprecation + Enhancement

Description

CableReady's render operations: ActionController renderer doesn't indicate that it's coming/being used for CableReady operations. This pull request renames the renderer to render cable_ready: and adds a deprecation warning for the operations renderer.

Additionally it make the DX around it a little bit better by checking if the passed argument responds to .dispatch before calling it. This helps when you already called .dispatch in the controller action or if you provide it a already converted JSON string.

This pull request also changes the cable_ready MIME type from application/vnd.cable-ready.json to text/vnd.cable-ready.json so that the response from a controller action can be viewed in a browser.

Finally, this pull request adds the X-Cable-Ready-Version header to the response.

Screenshot 2023-03-04 at 14 11 07

Why should this be added

This is an effort to keep the naming consistent and scope all CableReady functions with its own name. Following up on #259, #252 and #250.

Checklist

  • My code follows the style guidelines of this project
  • Checks (StandardRB & Prettier-Standard) are passing

@marcoroth marcoroth requested a review from julianrubisch March 1, 2023 07:43
@netlify
Copy link

netlify bot commented Mar 1, 2023

Deploy Preview for cableready ready!

Name Link
🔨 Latest commit
🔍 Latest deploy log https://app.netlify.com/sites/cableready/deploys/640b8ebdfca669006d3cc53a
😎 Deploy Preview https://deploy-preview-260--cableready.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@marcoroth marcoroth changed the title Deprecate operations ActionController renderer in favor of cable_ready Rework CableReady's ActionController::Renderers Mar 4, 2023
Mime::Type.register "application/vnd.cable-ready.json", :cable_ready
ActionController::Renderers.add :cable_ready do |operations, options|
response.content_type ||= Mime[:cable_ready]
response.headers["X-Cable-Ready-Version"] = CableReady::VERSION
Copy link
Contributor

Choose a reason for hiding this comment

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

The addition of the version header will be helpful.

@marcoroth marcoroth merged commit e442511 into main Mar 10, 2023
@marcoroth marcoroth deleted the deprecate-operations-action-controller-renderer branch March 10, 2023 20:20
jibees added a commit to jibees/mrujs that referenced this pull request Mar 30, 2023
Since stimulusreflex/cable_ready#260, `cable_ready` changed its Content-Type to `text/vnd.cable-ready.json`.
This commit updates the default one used to be compatible with `cable_ready`.
KonnorRogers pushed a commit to KonnorRogers/mrujs that referenced this pull request May 25, 2023
…ready`: `text/vnd.cable-ready.json` (#209)

* Update default Content-Type to reflect the one used by `cable_ready`

Since stimulusreflex/cable_ready#260, `cable_ready` changed its Content-Type to `text/vnd.cable-ready.json`.
This commit updates the default one used to be compatible with `cable_ready`.

* Add some documentation about how `Accept` header can be modified
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants