Module: WhereIsWaldo::Broadcastable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/where_is_waldo/broadcastable.rb
Overview
Opt a model into real-time broadcasting. Include the concern and declare which lifecycle events should push over the cable:
class Person < ApplicationRecord
include WhereIsWaldo::Broadcastable
broadcasts_realtime # create + update + destroy
end
broadcasts_realtime on: %i[create update] # subset
broadcasts_realtime on: :update, if: -> { saved_change_to_status? }
broadcasts_realtime scope: ->(rec) { rec.organization.users }
Event names follow "
Audience defaults to WhereIsWaldo.configuration.broadcast_audience (set
once per app, e.g. ->(rec) { rec.account.users }); override per model with
scope:. Payload defaults to a minimal { id: } (so clients refetch);
override realtime_payload on the model to push a richer shape for
patch-in-place rendering.
Constant Summary collapse
- HOOKS =
{ create: %i[after_create_commit created], update: %i[after_update_commit update], destroy: %i[after_destroy_commit destroyed] }.freeze
Instance Method Summary collapse
-
#realtime_payload ⇒ Object
Override on the model to shape the payload (default: minimal { id: }).
Instance Method Details
#realtime_payload ⇒ Object
Override on the model to shape the payload (default: minimal { id: }).
48 49 50 |
# File 'app/models/concerns/where_is_waldo/broadcastable.rb', line 48 def realtime_payload { id: id } end |