Skip to content

Commit 19dc823

Browse files
cpsievertgadenbuie
andauthored
Update js/chat/chat.ts
Co-authored-by: Garrick Aden-Buie <garrick@posit.co>
1 parent d9103c8 commit 19dc823

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

js/chat/chat.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -528,21 +528,19 @@ class ChatContainer extends LightElement {
528528

529529
// ------- Register custom elements and shiny bindings ---------
530530

531-
if (!customElements.get(CHAT_MESSAGE_TAG)) {
532-
customElements.define(CHAT_MESSAGE_TAG, ChatMessage);
533-
}
534-
if (!customElements.get(CHAT_USER_MESSAGE_TAG)) {
535-
customElements.define(CHAT_USER_MESSAGE_TAG, ChatUserMessage);
536-
}
537-
if (!customElements.get(CHAT_MESSAGES_TAG)) {
538-
customElements.define(CHAT_MESSAGES_TAG, ChatMessages);
539-
}
540-
if (!customElements.get(CHAT_INPUT_TAG)) {
541-
customElements.define(CHAT_INPUT_TAG, ChatInput);
542-
}
543-
if (!customElements.get(CHAT_CONTAINER_TAG)) {
544-
customElements.define(CHAT_CONTAINER_TAG, ChatContainer);
545-
}
531+
const chatCustomElements = [
532+
{ tag: CHAT_MESSAGE_TAG, component: ChatMessage },
533+
{ tag: CHAT_USER_MESSAGE_TAG, component: ChatUserMessage },
534+
{ tag: CHAT_MESSAGES_TAG, component: ChatMessages },
535+
{ tag: CHAT_INPUT_TAG, component: ChatInput },
536+
{ tag: CHAT_CONTAINER_TAG, component: ChatContainer }
537+
];
538+
539+
chatCustomElements.forEach(({ tag, component }) => {
540+
if (!customElements.get(tag)) {
541+
customElements.define(tag, component);
542+
}
543+
});
546544

547545
window.Shiny.addCustomMessageHandler(
548546
"shinyChatMessage",

0 commit comments

Comments
 (0)