Module: Turbo::Train::Broadcastable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/turbo/train/broadcastable.rb
Overview
Based on: Turbo::Broadcastable
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#train_broadcast_action(action, target: train_broadcast_target_default, **rendering) ⇒ Object
Same as
#train_broadcast_action_to
, but the designated stream is automatically set to the current model. -
#train_broadcast_action_later(action:, target: train_broadcast_target_default, **rendering) ⇒ Object
Same as
#train_broadcast_action_later_to
, but the designated stream is automatically set to the current model. -
#train_broadcast_action_later_to(*streamables, action:, target: train_broadcast_target_default, **rendering) ⇒ Object
Same as
train_broadcast_action_to
but run asynchronously via aTurbo::Streams::BroadcastJob
. -
#train_broadcast_action_to(*streamables, action:, target: train_broadcast_target_default, **rendering) ⇒ Object
Broadcast a named
action
, allowing for dynamic dispatch, instead of using the concrete action methods. -
#train_broadcast_after_to(*streamables, target:, **rendering) ⇒ Object
Insert a rendering of this broadcastable model after the target identified by it’s dom id passed as
target
for subscribers of the stream name identified by the passedstreamables
. -
#train_broadcast_append(target: train_broadcast_target_default, **rendering) ⇒ Object
Same as
#train_broadcast_append_to
, but the designated stream is automatically set to the current model. -
#train_broadcast_append_later(target: train_broadcast_target_default, **rendering) ⇒ Object
Same as
#train_broadcast_append_later_to
, but the designated stream is automatically set to the current model. -
#train_broadcast_append_later_to(*streamables, target: train_broadcast_target_default, **rendering) ⇒ Object
Same as
train_broadcast_append_to
but run asynchronously via aTurbo::Streams::BroadcastJob
. -
#train_broadcast_append_to(*streamables, target: train_broadcast_target_default, **rendering) ⇒ Object
Append a rendering of this broadcastable model to the target identified by it’s dom id passed as
target
for subscribers of the stream name identified by the passedstreamables
. -
#train_broadcast_before_to(*streamables, target:, **rendering) ⇒ Object
Insert a rendering of this broadcastable model before the target identified by it’s dom id passed as
target
for subscribers of the stream name identified by the passedstreamables
. -
#train_broadcast_prepend(target: train_broadcast_target_default, **rendering) ⇒ Object
Same as
#train_broadcast_prepend_to
, but the designated stream is automatically set to the current model. -
#train_broadcast_prepend_later(target: train_broadcast_target_default, **rendering) ⇒ Object
Same as
#train_broadcast_prepend_later_to
, but the designated stream is automatically set to the current model. -
#train_broadcast_prepend_later_to(*streamables, target: train_broadcast_target_default, **rendering) ⇒ Object
Same as
train_broadcast_prepend_to
but run asynchronously via aTurbo::Streams::BroadcastJob
. -
#train_broadcast_prepend_to(*streamables, target: train_broadcast_target_default, **rendering) ⇒ Object
Prepend a rendering of this broadcastable model to the target identified by it’s dom id passed as
target
for subscribers of the stream name identified by the passedstreamables
. -
#train_broadcast_remove ⇒ Object
Same as
#train_broadcast_remove_to
, but the designated stream is automatically set to the current model. -
#train_broadcast_remove_to(*streamables, target: self) ⇒ Object
Remove this broadcastable model from the dom for subscribers of the stream name identified by the passed streamables.
-
#train_broadcast_render(**rendering) ⇒ Object
Render a turbo stream template with this broadcastable model passed as the local variable.
-
#train_broadcast_render_later(**rendering) ⇒ Object
Same as
train_broadcast_action_to
but run asynchronously via aTurbo::Streams::BroadcastJob
. -
#train_broadcast_render_later_to(*streamables, **rendering) ⇒ Object
Same as
train_broadcast_render_later
but run with the added option of naming the stream using the passedstreamables
. -
#train_broadcast_render_to(*streamables, **rendering) ⇒ Object
Same as
train_broadcast_render
but run with the added option of naming the stream using the passedstreamables
. -
#train_broadcast_replace(**rendering) ⇒ Object
Same as
#train_broadcast_replace_to
, but the designated stream is automatically set to the current model. -
#train_broadcast_replace_later(**rendering) ⇒ Object
Same as
#train_broadcast_replace_later_to
, but the designated stream is automatically set to the current model. -
#train_broadcast_replace_later_to(*streamables, **rendering) ⇒ Object
Same as
train_broadcast_replace_to
but run asynchronously via aTurbo::Streams::BroadcastJob
. -
#train_broadcast_replace_to(*streamables, **rendering) ⇒ Object
Replace this broadcastable model in the dom for subscribers of the stream name identified by the passed
streamables
. -
#train_broadcast_update(**rendering) ⇒ Object
Same as
#broadcast_update_to
, but the designated stream is automatically set to the current model. -
#train_broadcast_update_later(**rendering) ⇒ Object
Same as
#train_broadcast_update_later_to
, but the designated stream is automatically set to the current model. -
#train_broadcast_update_later_to(*streamables, **rendering) ⇒ Object
Same as
train_broadcast_update_to
but run asynchronously via aTurbo::Streams::BroadcastJob
. -
#train_broadcast_update_to(*streamables, **rendering) ⇒ Object
Update this broadcastable model in the dom for subscribers of the stream name identified by the passed
streamables
.
Instance Method Details
#train_broadcast_action(action, target: train_broadcast_target_default, **rendering) ⇒ Object
Same as #train_broadcast_action_to
, but the designated stream is automatically set to the current model.
181 182 183 |
# File 'app/models/concerns/turbo/train/broadcastable.rb', line 181 def train_broadcast_action(action, target: train_broadcast_target_default, **rendering) train_broadcast_action_to self, action: action, target: target, **rendering end |
#train_broadcast_action_later(action:, target: train_broadcast_target_default, **rendering) ⇒ Object
Same as #train_broadcast_action_later_to
, but the designated stream is automatically set to the current model.
232 233 234 |
# File 'app/models/concerns/turbo/train/broadcastable.rb', line 232 def train_broadcast_action_later(action:, target: train_broadcast_target_default, **rendering) train_broadcast_action_later_to self, action: action, target: target, **rendering end |
#train_broadcast_action_later_to(*streamables, action:, target: train_broadcast_target_default, **rendering) ⇒ Object
Same as train_broadcast_action_to
but run asynchronously via a Turbo::Streams::BroadcastJob
.
227 228 229 |
# File 'app/models/concerns/turbo/train/broadcastable.rb', line 227 def train_broadcast_action_later_to(*streamables, action:, target: train_broadcast_target_default, **rendering) Turbo::Train.broadcast_action_later_to(*streamables, action: action, target: target, **train_broadcast_rendering_with_defaults(rendering)) end |
#train_broadcast_action_to(*streamables, action:, target: train_broadcast_target_default, **rendering) ⇒ Object
Broadcast a named action
, allowing for dynamic dispatch, instead of using the concrete action methods. Examples:
# Sends <turbo-stream action="prepend" target="clearances"><template><div id="clearance_5">My Clearance</div></template></turbo-stream>
# to the stream named "identity:2:clearances"
clearance.train_broadcast_action_to examiner.identity, :clearances, action: :prepend, target: "clearances"
176 177 178 |
# File 'app/models/concerns/turbo/train/broadcastable.rb', line 176 def train_broadcast_action_to(*streamables, action:, target: train_broadcast_target_default, **rendering) Turbo::Train.broadcast_action_to(*streamables, action: action, target: target, **train_broadcast_rendering_with_defaults(rendering)) end |
#train_broadcast_after_to(*streamables, target:, **rendering) ⇒ Object
Insert a rendering of this broadcastable model after the target identified by it’s dom id passed as target
for subscribers of the stream name identified by the passed streamables
. The rendering parameters can be set by appending named arguments to the call. Examples:
# Sends <turbo-stream action="after" target="clearance_5"><template><div id="clearance_6">My Clearance</div></template></turbo-stream>
# to the stream named "identity:2:clearances"
clearance.train_broadcast_after_to examiner.identity, :clearances, target: "clearance_5"
# Sends <turbo-stream action="after" target="clearance_5"><template><div id="clearance_6">Other partial</div></template></turbo-stream>
# to the stream named "identity:2:clearances"
clearance.train_broadcast_after_to examiner.identity, :clearances, target: "clearance_5",
partial: "clearances/other_partial", locals: { a: 1 }
125 126 127 |
# File 'app/models/concerns/turbo/train/broadcastable.rb', line 125 def train_broadcast_after_to(*streamables, target:, **rendering) Turbo::Train.broadcast_after_to(*streamables, target: target, **train_broadcast_rendering_with_defaults(rendering)) end |
#train_broadcast_append(target: train_broadcast_target_default, **rendering) ⇒ Object
Same as #train_broadcast_append_to
, but the designated stream is automatically set to the current model.
146 147 148 |
# File 'app/models/concerns/turbo/train/broadcastable.rb', line 146 def train_broadcast_append(target: train_broadcast_target_default, **rendering) train_broadcast_append_to self, target: target, **rendering end |
#train_broadcast_append_later(target: train_broadcast_target_default, **rendering) ⇒ Object
Same as #train_broadcast_append_later_to
, but the designated stream is automatically set to the current model.
212 213 214 |
# File 'app/models/concerns/turbo/train/broadcastable.rb', line 212 def train_broadcast_append_later(target: train_broadcast_target_default, **rendering) train_broadcast_append_later_to self, target: target, **rendering end |
#train_broadcast_append_later_to(*streamables, target: train_broadcast_target_default, **rendering) ⇒ Object
Same as train_broadcast_append_to
but run asynchronously via a Turbo::Streams::BroadcastJob
.
207 208 209 |
# File 'app/models/concerns/turbo/train/broadcastable.rb', line 207 def train_broadcast_append_later_to(*streamables, target: train_broadcast_target_default, **rendering) Turbo::Train.broadcast_append_later_to(*streamables, target: target, **train_broadcast_rendering_with_defaults(rendering)) end |
#train_broadcast_append_to(*streamables, target: train_broadcast_target_default, **rendering) ⇒ Object
Append a rendering of this broadcastable model to the target identified by it’s dom id passed as target
for subscribers of the stream name identified by the passed streamables
. The rendering parameters can be set by appending named arguments to the call. Examples:
# Sends <turbo-stream action="append" target="clearances"><template><div id="clearance_5">My Clearance</div></template></turbo-stream>
# to the stream named "identity:2:clearances"
clearance.train_broadcast_append_to examiner.identity, :clearances, target: "clearances"
# Sends <turbo-stream action="append" target="clearances"><template><div id="clearance_5">Other partial</div></template></turbo-stream>
# to the stream named "identity:2:clearances"
clearance.train_broadcast_append_to examiner.identity, :clearances, target: "clearances",
partial: "clearances/other_partial", locals: { a: 1 }
141 142 143 |
# File 'app/models/concerns/turbo/train/broadcastable.rb', line 141 def train_broadcast_append_to(*streamables, target: train_broadcast_target_default, **rendering) Turbo::Train.broadcast_append_to(*streamables, target: target, **train_broadcast_rendering_with_defaults(rendering)) end |
#train_broadcast_before_to(*streamables, target:, **rendering) ⇒ Object
Insert a rendering of this broadcastable model before the target identified by it’s dom id passed as target
for subscribers of the stream name identified by the passed streamables
. The rendering parameters can be set by appending named arguments to the call. Examples:
# Sends <turbo-stream action="before" target="clearance_5"><template><div id="clearance_4">My Clearance</div></template></turbo-stream>
# to the stream named "identity:2:clearances"
clearance.train_broadcast_before_to examiner.identity, :clearances, target: "clearance_5"
# Sends <turbo-stream action="before" target="clearance_5"><template><div id="clearance_4">Other partial</div></template></turbo-stream>
# to the stream named "identity:2:clearances"
clearance.train_broadcast_before_to examiner.identity, :clearances, target: "clearance_5",
partial: "clearances/other_partial", locals: { a: 1 }
109 110 111 |
# File 'app/models/concerns/turbo/train/broadcastable.rb', line 109 def train_broadcast_before_to(*streamables, target:, **rendering) Turbo::Train.broadcast_before_to(*streamables, target: target, **train_broadcast_rendering_with_defaults(rendering)) end |
#train_broadcast_prepend(target: train_broadcast_target_default, **rendering) ⇒ Object
Same as #train_broadcast_prepend_to
, but the designated stream is automatically set to the current model.
167 168 169 |
# File 'app/models/concerns/turbo/train/broadcastable.rb', line 167 def train_broadcast_prepend(target: train_broadcast_target_default, **rendering) train_broadcast_prepend_to self, target: target, **rendering end |
#train_broadcast_prepend_later(target: train_broadcast_target_default, **rendering) ⇒ Object
Same as #train_broadcast_prepend_later_to
, but the designated stream is automatically set to the current model.
222 223 224 |
# File 'app/models/concerns/turbo/train/broadcastable.rb', line 222 def train_broadcast_prepend_later(target: train_broadcast_target_default, **rendering) train_broadcast_prepend_later_to self, target: target, **rendering end |
#train_broadcast_prepend_later_to(*streamables, target: train_broadcast_target_default, **rendering) ⇒ Object
Same as train_broadcast_prepend_to
but run asynchronously via a Turbo::Streams::BroadcastJob
.
217 218 219 |
# File 'app/models/concerns/turbo/train/broadcastable.rb', line 217 def train_broadcast_prepend_later_to(*streamables, target: train_broadcast_target_default, **rendering) Turbo::Train.broadcast_prepend_later_to(*streamables, target: target, **train_broadcast_rendering_with_defaults(rendering)) end |
#train_broadcast_prepend_to(*streamables, target: train_broadcast_target_default, **rendering) ⇒ Object
Prepend a rendering of this broadcastable model to the target identified by it’s dom id passed as target
for subscribers of the stream name identified by the passed streamables
. The rendering parameters can be set by appending named arguments to the call. Examples:
# Sends <turbo-stream action="prepend" target="clearances"><template><div id="clearance_5">My Clearance</div></template></turbo-stream>
# to the stream named "identity:2:clearances"
clearance.train_broadcast_prepend_to examiner.identity, :clearances, target: "clearances"
# Sends <turbo-stream action="prepend" target="clearances"><template><div id="clearance_5">Other partial</div></template></turbo-stream>
# to the stream named "identity:2:clearances"
clearance.train_broadcast_prepend_to examiner.identity, :clearances, target: "clearances",
partial: "clearances/other_partial", locals: { a: 1 }
162 163 164 |
# File 'app/models/concerns/turbo/train/broadcastable.rb', line 162 def train_broadcast_prepend_to(*streamables, target: train_broadcast_target_default, **rendering) Turbo::Train.broadcast_prepend_to(*streamables, target: target, **train_broadcast_rendering_with_defaults(rendering)) end |
#train_broadcast_remove ⇒ Object
Same as #train_broadcast_remove_to
, but the designated stream is automatically set to the current model.
55 56 57 |
# File 'app/models/concerns/turbo/train/broadcastable.rb', line 55 def train_broadcast_remove train_broadcast_remove_to self end |
#train_broadcast_remove_to(*streamables, target: self) ⇒ Object
Remove this broadcastable model from the dom for subscribers of the stream name identified by the passed streamables. Example:
# Sends <turbo-stream action="remove" target="clearance_5"></turbo-stream> to the stream named "identity:2:clearances"
clearance.train_broadcast_remove_to examiner.identity, :clearances
50 51 52 |
# File 'app/models/concerns/turbo/train/broadcastable.rb', line 50 def train_broadcast_remove_to(*streamables, target: self) Turbo::Train.broadcast_remove_to(*streamables, target: target) end |
#train_broadcast_render(**rendering) ⇒ Object
Render a turbo stream template with this broadcastable model passed as the local variable. Example:
# Template: entries/_entry.turbo_stream.erb
<%= turbo_stream.remove entry %>
<%= turbo_stream.append "entries", entry if entry.active? %>
Sends:
<turbo-stream action="remove" target="entry_5"></turbo-stream>
<turbo-stream action="append" target="entries"><template><div id="entry_5">My Entry</div></template></turbo-stream>
…to the stream named “entry:5”.
Note that rendering inline via this method will cause template rendering to happen synchronously. That is usually not desireable for model callbacks, certainly not if those callbacks are inside of a transaction. Most of the time you should be using ‘train_broadcast_render_later`, unless you specifically know why synchronous rendering is needed.
253 254 255 |
# File 'app/models/concerns/turbo/train/broadcastable.rb', line 253 def train_broadcast_render(**rendering) train_broadcast_render_to self, **rendering end |
#train_broadcast_render_later(**rendering) ⇒ Object
Same as train_broadcast_action_to
but run asynchronously via a Turbo::Streams::BroadcastJob
.
268 269 270 |
# File 'app/models/concerns/turbo/train/broadcastable.rb', line 268 def train_broadcast_render_later(**rendering) train_broadcast_render_later_to self, **rendering end |
#train_broadcast_render_later_to(*streamables, **rendering) ⇒ Object
Same as train_broadcast_render_later
but run with the added option of naming the stream using the passed streamables
.
274 275 276 |
# File 'app/models/concerns/turbo/train/broadcastable.rb', line 274 def train_broadcast_render_later_to(*streamables, **rendering) Turbo::Train.broadcast_render_later_to(*streamables, **train_broadcast_rendering_with_defaults(rendering)) end |
#train_broadcast_render_to(*streamables, **rendering) ⇒ Object
Same as train_broadcast_render
but run with the added option of naming the stream using the passed streamables
.
Note that rendering inline via this method will cause template rendering to happen synchronously. That is usually not desireable for model callbacks, certainly not if those callbacks are inside of a transaction. Most of the time you should be using ‘train_broadcast_render_later_to`, unless you specifically know why synchronous rendering is needed.
263 264 265 |
# File 'app/models/concerns/turbo/train/broadcastable.rb', line 263 def train_broadcast_render_to(*streamables, **rendering) Turbo::Train.broadcast_render_to(*streamables, **train_broadcast_rendering_with_defaults(rendering)) end |
#train_broadcast_replace(**rendering) ⇒ Object
Same as #train_broadcast_replace_to
, but the designated stream is automatically set to the current model.
74 75 76 |
# File 'app/models/concerns/turbo/train/broadcastable.rb', line 74 def train_broadcast_replace(**rendering) train_broadcast_replace_to self, **rendering end |
#train_broadcast_replace_later(**rendering) ⇒ Object
Same as #train_broadcast_replace_later_to
, but the designated stream is automatically set to the current model.
192 193 194 |
# File 'app/models/concerns/turbo/train/broadcastable.rb', line 192 def train_broadcast_replace_later(**rendering) train_broadcast_replace_later_to self, **rendering end |
#train_broadcast_replace_later_to(*streamables, **rendering) ⇒ Object
Same as train_broadcast_replace_to
but run asynchronously via a Turbo::Streams::BroadcastJob
.
187 188 189 |
# File 'app/models/concerns/turbo/train/broadcastable.rb', line 187 def train_broadcast_replace_later_to(*streamables, **rendering) Turbo::Train.broadcast_replace_later_to(*streamables, target: self, **train_broadcast_rendering_with_defaults(rendering)) end |
#train_broadcast_replace_to(*streamables, **rendering) ⇒ Object
Replace this broadcastable model in the dom for subscribers of the stream name identified by the passed streamables
. The rendering parameters can be set by appending named arguments to the call. Examples:
# Sends <turbo-stream action="replace" target="clearance_5"><template><div id="clearance_5">My Clearance</div></template></turbo-stream>
# to the stream named "identity:2:clearances"
clearance.train_broadcast_replace_to examiner.identity, :clearances
# Sends <turbo-stream action="replace" target="clearance_5"><template><div id="clearance_5">Other partial</div></template></turbo-stream>
# to the stream named "identity:2:clearances"
clearance.train_broadcast_replace_to examiner.identity, :clearances, partial: "clearances/other_partial", locals: { a: 1 }
69 70 71 |
# File 'app/models/concerns/turbo/train/broadcastable.rb', line 69 def train_broadcast_replace_to(*streamables, **rendering) Turbo::Train.broadcast_replace_to(*streamables, target: self, **train_broadcast_rendering_with_defaults(rendering)) end |
#train_broadcast_update(**rendering) ⇒ Object
Same as #broadcast_update_to
, but the designated stream is automatically set to the current model.
93 94 95 |
# File 'app/models/concerns/turbo/train/broadcastable.rb', line 93 def train_broadcast_update(**rendering) train_broadcast_update_to self, **rendering end |
#train_broadcast_update_later(**rendering) ⇒ Object
Same as #train_broadcast_update_later_to
, but the designated stream is automatically set to the current model.
202 203 204 |
# File 'app/models/concerns/turbo/train/broadcastable.rb', line 202 def train_broadcast_update_later(**rendering) train_broadcast_update_later_to self, **rendering end |
#train_broadcast_update_later_to(*streamables, **rendering) ⇒ Object
Same as train_broadcast_update_to
but run asynchronously via a Turbo::Streams::BroadcastJob
.
197 198 199 |
# File 'app/models/concerns/turbo/train/broadcastable.rb', line 197 def train_broadcast_update_later_to(*streamables, **rendering) Turbo::Train.broadcast_update_later_to(*streamables, target: self, **train_broadcast_rendering_with_defaults(rendering)) end |
#train_broadcast_update_to(*streamables, **rendering) ⇒ Object
Update this broadcastable model in the dom for subscribers of the stream name identified by the passed streamables
. The rendering parameters can be set by appending named arguments to the call. Examples:
# Sends <turbo-stream action="update" target="clearance_5"><template><div id="clearance_5">My Clearance</div></template></turbo-stream>
# to the stream named "identity:2:clearances"
clearance.train_broadcast_update_to examiner.identity, :clearances
# Sends <turbo-stream action="update" target="clearance_5"><template><div id="clearance_5">Other partial</div></template></turbo-stream>
# to the stream named "identity:2:clearances"
clearance.train_broadcast_update_to examiner.identity, :clearances, partial: "clearances/other_partial", locals: { a: 1 }
88 89 90 |
# File 'app/models/concerns/turbo/train/broadcastable.rb', line 88 def train_broadcast_update_to(*streamables, **rendering) Turbo::Train.broadcast_update_to(*streamables, target: self, **train_broadcast_rendering_with_defaults(rendering)) end |