Skip to content

Instantly share code, notes, and snippets.

@tvaisanen
Created May 10, 2022 16:41
Show Gist options
  • Save tvaisanen/a23001adfd62f772978fac4a9cec95f9 to your computer and use it in GitHub Desktop.
Save tvaisanen/a23001adfd62f772978fac4a9cec95f9 to your computer and use it in GitHub Desktop.
ClojureScript Web Component: Extend js/HTMLElement
(defn MyElement
{:jsdoc ["@constructor"]}
[t]
;; class MyElement extends HTMLElement {}
(js/Reflect.setPrototypeOf
(.-prototype MyElement)
(.-prototype js/HTMLElement))
(js/Reflect.setPrototypeOf
MyElement
js/HTMLElement)
(let [this (apply js/Reflect.construct [js/HTMLElement #js [] MyElement])]
(set! (.-innerText this) "FOO")
(set! (.-observedAttributes MyElement) #js ["class"])
this))
(js/window.customElements.define "my-element" MyElement)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment