2023-02-04 14:22:05 +01:00
|
|
|
import consumer from "./consumer"
|
|
|
|
|
2023-02-05 21:01:07 +01:00
|
|
|
const count_channel = consumer.subscriptions.create("CountChannel", {
|
2023-02-04 14:22:05 +01:00
|
|
|
connected() {
|
|
|
|
// Called when the subscription is ready for use on the server
|
|
|
|
console.warn("Connected to CountChannel.");
|
|
|
|
},
|
|
|
|
|
|
|
|
disconnected() {
|
|
|
|
// Called when the subscription has been terminated by the server
|
|
|
|
},
|
|
|
|
|
|
|
|
received(data) {
|
|
|
|
// Called when there's incoming data on the websocket for this channel
|
2023-02-05 21:01:07 +01:00
|
|
|
console.log(data)
|
|
|
|
if (data.update !== undefined)
|
|
|
|
this.update(data.update)
|
|
|
|
|
|
|
|
if (data.destroy !== undefined)
|
|
|
|
this.destroy(data.destroy)
|
|
|
|
},
|
|
|
|
|
|
|
|
update(data) {
|
|
|
|
$("[data-count-id='"+ data.id + "'] .count").text(data.count)
|
|
|
|
$("[data-count-id='"+ data.id + "'] .name").text(data.name)
|
|
|
|
},
|
|
|
|
|
|
|
|
destroy(data) {
|
|
|
|
$("[data-count-id='"+ data + "']").remove()
|
|
|
|
},
|
2023-02-04 14:22:05 +01:00
|
|
|
});
|
2023-02-05 21:01:07 +01:00
|
|
|
|
|
|
|
$(document).on('turbo:load', function() {
|
|
|
|
if (count_channel !== undefined && !count_channel.consumer.connection.disconnected) {
|
|
|
|
$("")
|
|
|
|
}
|
|
|
|
})
|