[Cable] Support the stream_for
and broadcast_to
methods
#121
Labels
good first issue
Good for newcomers
stream_for
and broadcast_to
methods
#121
Description
Currently, Rage only supports creating streams using the
stream_from
method. Implementingstream_for
would allow users to create streams based on the(channel, object)
pair.Example:
The following code will create a stream with the name based on the name of the channel and the object identifier.
Later,
broadcast_to
can be used to post messages to this stream:How to build object identifiers
To automatically create a stream based on the
(channel, object)
pair, we need to generate an identifier forobject
. The process of creating object identifiers should be performant and consistent across different servers (which is why we can’t useobject_id
). Additionally,stream_for
should accept any Ruby objects, not just ActiveRecord models.Using
#id
for ActiveRecord models and#as_json.to_s
for non-ActiveRecord objects should satisfy the requirements, but I’m also open to other suggestions.Tips
nil
as this is unlikely something users will ever do intentionally.The text was updated successfully, but these errors were encountered: