Skip to content

Conversation

@mrrooijen
Copy link

Currently, broadcasts_refreshes only accepts values in the form of a string or nil, where explicitly passing nil bypasses broadcasting but still triggers the after_create_commit callback.

This change allows you to pass a symbol (method name to call) or a proc to evaluate to broadcasts_refreshes to produce a stream name dynamically at the instance level after_create_commit.

This allows us to, for example, specify a parent (Board) to broadcast refreshes to on create, while broadcasting to itself (Column) on update and destroy:

class Column < ApplicationRecord
  belongs_to :board
  broadcasts_refreshes :board
end

Listen for new Column creations for @board:

<%= turbo_stream_from @board %> 

Listen for updates and deletion of existing @column:

<%= turbo_stream_from @column %> 

This changes also disables the entire after_create_commit hook if nil is passed in explicitly, rather than allowing it to run without broadcasting anything.

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.

1 participant