StimulusReflex is an implementation for classic Rails architecture: Server sends a whole HTML to the browser, the browser displays it as is, JS listens to user’s input, notifies about them the server (Stimulus), server reacts on them appropriately and responds with a new page, or a piece of page to be rerendered (Reflex).
class CustomersReflex < ApplicationReflex
def facet
filter = CustomerFilter.find(element.dataset.filter)
yield filter
pagy, customers = pagy(filter.scope, page: filter.page, items: filter.items)
morph customers
morph "#paginator", render(partial: "customers/paginator", locals: {pagy: pagy, filter: filter})
end
end
class CustomersReflex < ApplicationReflex
def facet
filter = CustomerFilter.find(element.dataset.filter)
yield filter
pagy, customers = pagy(filter.scope, page: filter.page, items: filter.items)
morph customers
morph "#paginator", render(partial: "customers/paginator", locals: {pagy: pagy, filter: filter})
end
end
All state is maintained by the server. Any updated view content is automatically morphed on the client. No need for duplicating business logic on front-end side and keeping it synced with the server.
StimulusReflex uses Ruby. A stable, well-maintained, robust language. Front-end side uses HTML and lightweight JavaScript generated by the server. JavaScript only monitors user inputs and notifies the server.
Server composing a whole page code as HTML. No need for reimplementing basic web functionality in JavaScript.
You need only Redis or another DB. No GraphQL, Apollo, Redux, and other moving parts.
StimulusReflex is extremely well documented with current samples. Use Discord community for any additional questions.
Smaller team is needed. Since no logic is implemented on the front-end side, the front end teem is much smaller and does pretty isolated tasks. One person can confidently implement and deploy a complex feature.
For playground projects, use ActionCable – a default Rails module which is easy to start with.
For production ready projects, use AnyCable. It outperforms ActionCable and gives you a real Real-time.
For high-loaded projects, use AnyCable Pro. It reduces memory usage, saves bandwidth and gives priority support by the developers.
HTML is rendered immediately by the browser, no intermediate JSON parsing.
Round-trip actions and updates typically occur in 10-25ms, depending on geography.
Works greate on any, even the oldest ones, modile devices.
Front-end part of the app is 10x smaller than while using React.
Client sends light-weight notifications. Data transferring is well-optimized.
Very little CPU activity when serving HTML content to a browser save battery from draining.
One full stack Rails developer can build a single codebase that serves web and native mobile.
Less inter-team communication causes less delay and time to make an agreement.
Good documentations allow quick start and speeds up the development.
Less inter-team communication causes less delay and time to make an agreement.
Good documentations allow quick start and speeds up the development.
More responsive screens, simpler code, amazing support.
What matters is your productivity and how much you enjoy working with a library. I found myself very productive, and I really enjoyed it.
SR saved my day, my (chunky) bacon, my sanity, my dignity, and who knows what else! What a time to be alive!
If your application should work in offline mode, stick with React approach.
Games and other highly interactive apps are not best fit to StimulusReflex.
JS devs may find it hard to learn Rails.