Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A productive library for Classic Rails, React and Redux

License

NotificationsYou must be signed in to change notification settings

thoughtbot/superglue

Logo

Superglue

Use classic Rails to build rich React Redux applications withNO APIs andNO client-side routing.

Test superglue_js

Superglue makes React and Redux as productive as Hotwire, Turbo and Stimulus.Its inspired by Turbolinks and designed to feel like a natural extension ofRails. Enjoy the benefits of Redux state management and React componentswithout giving up the productivity of Rails form helpers, UJS, tag helpers,flash, cookie auth, and more.

No APIs

Instead of APIs, Superglue leans on Rails' ability to respond to differentmime typeson the same route. In a Superglue application, if you direct your browser to/dashboard.html, you would see the HTML version of the content, and if youwent to/dashboard.json you would see the JSON version of the exact samecontent down to the footer.

The end result would be something like this:

No Apis

Powered by Classic Rails

Superglue leans on Rails. Features like the flash, cookie auth, and URLhelpers continue to be useful. Here's a look at the directory structure of atypical Rails application with Superglue.

app/|-- controllers/|-- views/|   |-- dashboard/|   |   |-- index.jsx # The React page component|   |   |-- index.json.props # The json for the page component|   |   |-- index.html.erb

PropsTemplate

Powering the JSON responses is PropsTemplate, a diggable JSON templating DSLinspired by JBuilder. With PropsTemplate you can specify a path of the node youwant, and PropsTemplate will walk the tree to it, skipping the execution of nodesthat don't match the keypath.

No Apis

All together now!

Superglue comes with batteries that bring all the above concepts together to makebuilding popular SPA features easy, painless, and productive.

SPA Navigation

A popular ask of SPAs is page-to-page navigation without reloading. This iseasily done with Superglue's own UJS attributes inspired by Turbolinks:

<ahref='/posts'data-sg-visit/>

The above will request for/posts with anaccept ofapplication/json, andwhen the client receives the response, swap out the current component for thecomponent the response asks for, andpushState on history.

Easy Partial updates

Some features rely on updating some parts of the existing page. Imagineimplementing type-ahead search. In traditional applications, you may need a newcontroller, routes, a discussion over versioning, JSON serializer, plenty ofnew JS code, etc.

haircuts

With Superglue, this can be done with a simpleonChange

import{NavigationContext}from'@thoughtbot/superglue'const{remote}=useContext(NavigationContext)constonChange=(e)=>(remote(`/dashboard?qry=${e.target.value}&props_at=data.header.search`)})

Withprops_at, the above will make a request to/dashboard?qry=haircut,dig your template for thedata.header.search node, return it in the response,and immutably graft it in the exact same path on the redux store before finallyletting React re-render.

For more on what you can do, check out our documentation.

Server-Side Rendering

Server-Side Rendering is supported viaHumid.See thedocumentation for server-side rendering.

Documentation

Documentation is hosted onGitHub pages.

Contributing

Please seeCONTRIBUTING.md.

Thank you,contributors!

Special Thanks

Thanks tojbuilder,scour,turbolinks3,turbograft,turbostreamer

Sponsor this project

 

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp