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

What is the purpose of Turbo::Broadcastable::broadcasts ? #171

Closed
fig opened this issue May 5, 2021 · 1 comment
Closed

What is the purpose of Turbo::Broadcastable::broadcasts ? #171

fig opened this issue May 5, 2021 · 1 comment

Comments

@fig
Copy link
Contributor

fig commented May 5, 2021

From my reading of the documentation, the class method broadcasts should configure the model to broadcast creates, updates, and destroys to a stream name automatically set to the current model. I would expect the broadcasts to be made to a stream name derived from the model name pluralised, although the pluralisation is not documented explicitly.

In any case, the actual implementation broadcasts to a stream name derived from the GlobalID of the model instance. This makes little sense because although a partial can be configured to accept broadcasts from this unique stream name, updates will replace the target element as expected, destroys will leave an orphaned turbo-cable-stream-source tag behind and creating a new model instance has no effect because the broadcast will be made to a channel name that does not exist at the time of rendering.

What are community's thoughts on this?

Apologies if this is the wrong place to ask.

@ghost
Copy link

ghost commented Jun 4, 2021

Let's take this to https://discuss.hotwire.dev/.

(Briefly, though, I think what you’re describing is, say, broadcasts_to :posts. That’s not what broadcasts is for. Imagine you had a post that had comments that broadcasts_to :posts, but it’s important, for some reason, to broadcast when the title of the post changes. That’s when you’d reach for broadcasts. The <%= turbo_stream_from @post %> call in your template would pick up both the comments and the change to the post itself. And it would only be the changes to, and the comments for, that specific post, because the stream is scoped by the ID.)

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

No branches or pull requests

2 participants