CableReady.perform()inside an operation.
CableReady::BroadcasterConcern now provides a
cable_carmethod (in addition to the familiar
cable_readymethod) which you can call anywhere in your application.
cable_carto chain together operations which will ultimately be converted into JSON that the CableReady client can process.
Channels- which are delivered over WebSockets - Cable Car isn't opinionated about how you plan to use the JSON it creates. It doesn't have any broadcast capacity of its own, making it a perfect fit for controller actions responding to HTTP requests, ActiveJob scheduling and even persisting operations to your database.
cable_caris very similar to using the
cable_readymethod, except that there is no stream identifier ("no square brackets"). Instead of sending data with
broadcast, you generate JSON with
operationsis an Array that describes a batch of queued operations.
operationwhich identifies the operation type. Depending on the operation, additional
to_jsonmethod and send it to the client via the mechanism of your choice:
CableReady.perform()and the operations will be executed, regardless of how they got to the the browser.
cable_carand add operations multiple times, and it will continue to accumulate operations until you do something to clear the queue. Like the
dispatchaccepts an optional boolean keyword argument
clear, which you can use to return the current JSON blob without clearing the queue.
fetchis a snap. We need a button to kick things off, and an empty DIV element named
usersto receive updates. The button calls
goon a Stimulus controller:
cable_carmethod chain produces a Hash that represents all of your queued operations. What if you are not quite ready to send those updates, or want to save them in your database?