JSPM

@diax-js/custom-element

0.3.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 11
  • Score
    100M100P100Q58411F
  • License MIT

Simple implementation of Custom Elements.

Package Exports

  • @diax-js/custom-element
  • @diax-js/custom-element/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@diax-js/custom-element) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@diax-js/custom-element

This package provides implementation of custom element.

How to use

Type in your terminal:

npm i @diax-js/custom-element

Component definition:

1. Using Decorators:

    import { CustomElement } from '@diax-js/custom-element'
    import { attachListener } from '@diax/context/host';

    @CustomElement('my-element')
    class MyElement {

        private name = 'My Element'

        constructor() {
            attachEventLister('dblclick', () => this.alert());
        }

        private alert() {
            alert(this.name);
        }
    }

2. Plain JS:

    import {getElementClass} from '@diax-js/custom-element';

    class MyElement {
        ... definition of the class as above
    }

    const HTMLCtor = getElementClass(MyElement);

    customElements.define('my-element', HTMLCtor);

Later in HTML:

    <my-element>
        Double click me
    </my-element>