Skip to content
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

Merged

Conversation

tonysm
Copy link
Contributor

@tonysm tonysm commented Nov 23, 2023

Fixed

  • In Support for page refreshes and broadcasting #499 a new 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 the broadcasts 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 a stream param to broadcasts_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 the broadcasts method works. It also sends the broadcast refresh right away instead of later when the model is deleted.

Comment on lines 1 to 5
class Board < ApplicationRecord
has_many :tasks

broadcasts_refreshes
end

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?

Copy link
Contributor Author

@tonysm tonysm Nov 23, 2023

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

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.

Copy link
Member

@jorgemanrubia jorgemanrubia left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants