mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-02-21 20:20:34 +09:00
23 lines
573 B
JavaScript
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 } })
|
|
}
|
|
}
|