mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-05-26 03:58:46 +09:00
Hello world
First open source release of Campfire 🎉
This commit is contained in:
22
app/javascript/controllers/read_rooms_controller.js
Normal file
22
app/javascript/controllers/read_rooms_controller.js
Normal file
@@ -0,0 +1,22 @@
|
||||
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 } })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user