Home

Awesome

builtin-elements

Coverage Status

<sup>Social Media Photo by zebbache djoubair on Unsplash</sup>

A zero friction custom elements like primitive.

import {HTML, SVG} from 'builtin-elements';

class MyButton extends HTML.Button {
  constructor(text) {
    super();
    this.textContent = text;
  }
}

document.body.appendChild(new MyButton('Hello!'));

Examples


API

This module exports the following utilities:

// full class features
class BuiltinElement extends HTML.Element {

  // exact same Custom Elements primitives
  static get observedAttributes() { return ['test']; }
  attributeChangedCallback(name, oldValue, newValue) {}
  connectedCallback() {}
  disconnectedCallback() {}

  // the best place to setup any component
  upgradedCallback() {}

  // the best place to teardown any component
  downgradedCallback() {}
}

When hydration is desired, upgradedCallback is the method to setup once all listeners, and if elements are subject to change extend, or be downgraded as regular element, downgradedCallback is the best place to cleanup listeners and/or anything else.