Skip to content

WebReflection/as-custom-element

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

As Custom Element

The easiest way to add Custom Elements like callbacks to any node.

Compatible with modern browsers, as well as IE11, and no polyfills are needed, for a minified size less than 0.8K.

import {upgrade, downgrade} from 'as-custom-element';

const someBehavior = {
  // lifecycle callbacks
  connectedCallback() {
    console.log(this, 'is connected');
  },
  disconnectedCallback() {},

  // attributes related helpers
  observedAttributes: ['one', 'or', 'more'],
  attributeChangedCallback(attributeName, oldValue, newValue) {}
};

upgrade(document.querySelector('#any'), someBehavior);

// to drop the behavior at any time
downgrade(document.querySelector('#any'), someBehavior);

About

Setup any element as if it was a Custom Element

Resources

License

Stars

Watchers

Forks

Packages

No packages published