All files / src/components/templated-item TemplatedItem.ts

71.43% Statements 5/7
100% Branches 0/0
50% Functions 1/2
71.43% Lines 5/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 461x 1x             1x       1x                                                                 1x
import CustomElement from "../../custom-element/CustomElement";
import defineCustomElement from "../../custom-element/helpers/defineCustomElement";
import { CustomElementPropertyMetadata } from "../../custom-element/interfaces";
import { NodePatchingData } from "../../renderer/NodePatcher";
 
/**
 * Component that uses data and a template to generate its content
 */
export default class TemplatedItem extends CustomElement {
 
    static get properties(): Record<string, CustomElementPropertyMetadata> {
 
        return {
 
            /**
             * The data used by the template to generate the markup
             */
            data: {
                type: [Object, Function],
                value: {}
                //required: true - We might need to load it after connecting the component
            },
 
            /**
             * The template to render the item
             */
            template: {
                type: Function,
                defer: true, // Store the function itself instead of executing it to get its return value when initializing the property
                required: true
            }
        }
    }
 
    render(): NodePatchingData {
 
        const {
            data,
            template
        } = this;
 
        return template(data);
    }
}
 
defineCustomElement('gcl-templated-item', TemplatedItem);