Comments (2)
Is there any status on this? Happy to help if any help is needed.
from stimulus_reflex.
Hi @pablo-co! We saw you join our Discord but you didn't seem to stick around long enough for us to connect there. We're a friendly bunch and I hope you drop by.
There is definitely progress, but it's from a different direction than you might be expecting. While I can't say conclusively, it's highly unlikely that this functionality will be added to StimulusReflex, because it's simply outside of the mandate of that project.
The great news is that SR is built atop CableReady (same author) which makes it relatively easy to pull off what you want to do. I'm going to be writing a blog post covering it, but here's the basics:
First, question whether what you really want is a redirection. Being on a page and then suddenly being on another page is a deeply jarring experience for a typical user. It's much more likely that you want to either refresh the page or update some element on it. CableReady gives you several options for doing this.
There are some places in my project where I want to force a refresh of the current page. On the server side, depending on whether my Channel class is a stream_for or stream_from, I use:
ProposalChannel.broadcast_to(Proposal.find(29),{})
(for)
or
ActionCable.server.broadcast("notification_1", {})
(from)
To generate an empty payload. And then in my Stimulus controller on the client:
import { Controller } from 'stimulus'
import StimulusReflex from 'stimulus_reflex'
import consumer from '../lib/consumer'
export default class extends Controller {
connect () {
this.element[this.identifier] = this
StimulusReflex.register(this)
if (this.element.dataset.id) {
const controller = this
consumer.subscriptions.create(
{
channel: 'ProposalChannel',
id: this.element.dataset.id
},
{
received () {
controller.stimulate('ApplicationReflex#refresh')
}
}
)
}
}
}
The ApplicationReflex itself is literally a no-op eg:
def refresh
# do nothing
end
This forces the client to refresh the current page as it would appear if the user hit Refresh. It's not as sexy as a built-in redirect (you could replace the controller.stimulate() call with a Turbolinks.visit() or even window.location) but it does what you need.
from stimulus_reflex.
Related Issues (20)
- Controller over reflex attribute is ignore and reflex is always called with default StimulusReflexController HOT 7
- Broken Next Page Link on Welcome Page of Docs HOT 2
- HEAD and most of the latest releases are broken, references an undefined exception
- StimulusReflex is not compatible with the standalone ActionCable server HOT 9
- Wrong dataset getting from Docs example HOT 2
- NameError: undefined local variable or method `package_json' HOT 3
- Reflex not triggered when a Stimulus controller is also attached to a field HOT 4
- Form parse errors are not captured and reported back to front-end
- Drop Rails 5 and 6.0 support
- `solid_cache` seems to work as well as Rails cache store HOT 1
- Add full-stack tests
- Stimulus_reflex and esbuild error HOT 1
- OpenStruct no longer supported by json HOT 1
- Refactor away instances of OpenStruct
- NameError: uninitialized constant StimulusReflex::Installer::Thor when running rake tasks HOT 1
- Support `relative_url_root`
- Could not find generator 'stimulus_reflex:initializer'
- Unrecognized command "esbuild" (Rails::Command::UnrecognizedCommandError)
- Installer should work in CI (noninteractive) environment
- docs recommend hiredis gem along with incompatible redis version
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stimulus_reflex.