26
loading...
This website collects cookies to deliver better user experience
cable_ready
singleton from just about anywhere in their application, and we believe it's a big part of the secret sauce. While every language and framework has their own idioms, we encourage implementors to remove barriers and make it easy to call CableReady anywhere it could be useful.[{\"message\":\"Hello!\",\"operation\":\"consoleLog\"}]
operation
value, or the client will raise an exception.cable_ready[:foo].operation(options).broadcast
cable_ready
starts a method chain by returning self
, and then each operation is a method that also returns the chain started by the initial method. In this way, you can chain together as many operations as you like. Finally, we have a broadcast
method which takes the current chain and broadcasts it via WebSockets to the :foo
channel.to_json
is called. This makes it perfect for responding to Ajax fetch requests:cable_car.operation(options).to_json
cable_car
might be assembled in steps, perhaps via a control loop:inspiration = cable_car.console_log(message: "Hello there!").dispatch_event(name: "fred", detail: {inspiring: true})
3.times do |i|
inspiration.console_log(message: "Still here: #{i}")
end
inspiration.to_json