-
Notifications
You must be signed in to change notification settings - Fork 329
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
Fix sending created broadcasts refreshes to channels where no one listens #521
Fix sending created broadcasts refreshes to channels where no one listens #521
Conversation
test/dummy/app/models/board.rb
Outdated
class Board < ApplicationRecord | ||
has_many :tasks | ||
|
||
broadcasts_refreshes | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is a new model necessary to test this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added one that actually uses the broadcasts_refreshes
. I'm not that versed in Rails, so pls let me know if there's another way to test this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think adding it to an existing model would work just as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice @tonysm, thanks for working on this one.
I like the additional model so that we can keep the other models isolated from these additional streams that will get triggered implicitly. I think that isolation is good for testing.
Fixed
broadcasts_refreshes
method was added that sets up the model hooks to send broadcasts refreshes automatically. However, it repeats the same issue previously found in thebroadcasts
method (Turbo::Broadcastable#broadcasts broadcasts creates to model_name.plural stream #295) where it sends the creation broadcasts to the current model's channel and defaults to, but no one will ever be listening on that. This PR allows passing astream
param tobroadcasts_refreshes
method, which will be used as the channel name when broadcasting refreshes on model creation and defaults to the model's plural name, similar to how thebroadcasts
method works. It also sends the broadcast refresh right away instead of later when the model is deleted.