Reputation: 55
So in my application using Rails 5 I have a loader system which caught ajaxSend
and ajaxComplete
to animate a loader in css.
$(document).bind('ajaxSend', () => {
...
})
$(document).bind('ajaxComplete', () => {
...
})
My question is simple, how to do the same thing with websockets ? :)
Upvotes: 1
Views: 82
Reputation: 4346
function connectToYourChannel () {
// start your animation here
subscription = App.cable.subscriptions.create("YourChannel") {
connected: function () {
// this code will execute when you successfully subscribe
// to your channel;
// end your animation here
}
}
}
BTW: the connection process is extremely fast. You won't need a loading message in 99% of cases.
Upvotes: 1