Skip to content

Instantly share code, notes, and snippets.

@thheller
Created November 20, 2016 09:19
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save thheller/36332574918b974a3e4996efcb7457d2 to your computer and use it in GitHub Desktop.
Save thheller/36332574918b974a3e4996efcb7457d2 to your computer and use it in GitHub Desktop.
create web-component v1 in cljs without class
(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