-
-
Save kevinmungai/42d9c99a8c7057eae1c92b19c93154c8 to your computer and use it in GitHub Desktop.
create web-component v1 in cljs without class
This file contains hidden or 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 component [] | |
(js/Reflect.construct js/HTMLElement #js [] component)) | |
(set! (.-prototype component) | |
(js/Object.create (.-prototype js/HTMLElement) | |
#js {:connectedCallback | |
#js {:configurable true | |
:value | |
(fn [] | |
(this-as this | |
(js/console.log "connected" this)))} | |
:disconnectedCallback | |
#js {:configurable true | |
:value | |
(fn [] | |
(this-as this | |
(js/console.log "disconnectedCallback" this)))} | |
:attributeChangedCallback | |
#js {:configurable true | |
:value | |
(fn [] | |
(this-as this | |
(js/console.log "attributeChangedCallback" this)))} | |
})) | |
(js/window.customElements.define "x-component" component) | |
(let [x (js/document.createElement "x-component")] | |
(js/document.body.appendChild x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment