1.1.1 • Published 7 months ago

@enhance/morphdom-mixin v1.1.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
7 months ago

enhance-morphdom-mixin

Enhance mixin to add Morphdom DOM diffing to a Custom Element

Install

npm i @enhance/morphdom-mixin

Usage

/pages/index.html

<my-header heading="My list"></my-header>

/elements/my-header.mjs

function MyHeader({ html, state  }) {
  const { attrs={} } = state
  const { heading='default' } = attrs
  return html`
    <style>
      :host h1 {
        font-size: 1.3rem;
        color: indigo;
      }
    </style>
    <h1>${heading}</h1>
    <p>${heading}</p>
    <a href="/foo/${heading}"></a>
  `
}

/browser/index.html

    class MyHeaderElement extends MorphdomMixin(CustomElement) {
      constructor() {
        super()
      }

      render(args) {
        return MyHeader(args)
      }

      static get observedAttributes() {
        return [ 'heading' ]
      }
    }
    customElements.define('my-header', MyHeaderElement)

Setting the heading attribute on the <my-header> element will trigger a re-render (scoped only to this element not the entire page) that will update all variables which avoids needing to manually write surgical DOM updates.

This approach, while convenient at times will not perform as well as surgical DOM updates.

1.1.1

7 months ago

1.1.0

7 months ago

1.0.3

7 months ago

1.0.2

7 months ago

1.0.0

8 months ago