-
Notifications
You must be signed in to change notification settings - Fork 298
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
Turbo 8: broadcasts_refreshes method doesn't propagate destroy or update by default #545
Comments
The updates are propagating correctly. Note that For turbo-rails/app/models/concerns/turbo/broadcastable.rb Lines 296 to 302 in 066396c
|
Please not that I am referring to parentless models. |
Yes, it's the expected behavior. You have to subscribe for each model. In that case, you can add under this line the following: <% @todos.each do |todo| %>
<%= turbo_stream_from todo %>
<% end %> And in the model simply This is because you may also want to subscribe to the I recommend you to check basecamp/turbo-8-morphing-demo |
I did check out that demo repo and looked at the implementation before I created my demo and this issue. Beta 1 had a different implementation and behaviour than current main branch. In the model:
In the view:
My point is that the behaviour (especially for quick demos) is a little unexpected from developers perspective. |
That's because you don't have a record before creation. If you want to react to the creation, say, be subscribed to the channel before it happens, it has to be a global stream. For the rest, there is already a record to subscribe to. See #521. |
Ok, that answer was helpful. So coming from the mindset that the usual case is to subscribe to a model with a parent anyways I can see why it's implemented like this. Guess we call it a close with comment for now. Thx for elaboration. |
The broadcasts_refreshes method should be of least surprise for developers in my opinion.
Let's say we subscribe to a parentless top level model.
Currently it is implemented like this:
Which basically means that it's not propagating the update and destroys.
Why is this? Is it because we assume that it always belongs to a parent?
To achieve full propagation of a parentless model I'd currently have to do something like this in the model:
broadcasts_refreshes_to ->(stream) { stream.class.broadcast_target_default }
Feels a little counter intuitive to me.
An alternative implementation that works for parentless collections would be this:
Is the current behaviour explicitly wanted?
If so would it make sense to create a method for parentless collections that propagates all commits implemented like the proposal?
I'd be more than happy to create a PR but let's first discuss.
Cheers Bijan
Note: broadcast_target_default is defined as a call to model_name.plural
Therefore it would be more consistent to use it as default parameter value (like in other methods)
The text was updated successfully, but these errors were encountered: