Files
once-campfire/app/javascript/controllers/read_rooms_controller.js
Kevin McConnell df76a227dc Hello world
First open source release of Campfire 🎉
2025-08-21 09:31:59 +01:00

23 lines
573 B
JavaScript

import { Controller } from "@hotwired/stimulus"
import { cable } from "@hotwired/turbo-rails"
import { ignoringBriefDisconnects } from "helpers/dom_helpers"
export default class extends Controller {
async connect() {
this.channel ??= await cable.subscribeTo({ channel: "ReadRoomsChannel" }, {
received: this.#read
})
}
disconnect() {
ignoringBriefDisconnects(this.element, () => {
this.channel?.unsubscribe()
this.channel = null
})
}
#read = ({ room_id }) => {
this.dispatch("read", { detail: { roomId: room_id } })
}
}