Created
May 10, 2022 16:41
-
-
Save tvaisanen/a23001adfd62f772978fac4a9cec95f9 to your computer and use it in GitHub Desktop.
ClojureScript Web Component: Extend js/HTMLElement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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