<commit_before>import { isFunction, isString } from '../lib/typeof.js';

/**
 * Simple Custom Component with template handling using the `template` property.
 *
 * @example
 * my-component.js
 * ```js
 * import { Component, TemplateMixin, mix } from 'dna/component';
 * export class MyComponent extends mix(Component).with(TemplateMixin) {
 *   get template() {
 *     return '<h1>${this.name}</h1>';
 *   }
 *   get name() {
 *     return 'Newton';
 *   }
 * }
 * ```
 * app.js
 * ```js
 * import { define } from 'dna/component';
 * import { MyComponent } from './components/my-component/my-component.js';
 * define('my-component', MyComponent);
 * var element = new MyComponent();
 * console.log(element.innerHTML); // logs "<h1>Newton</h1>"
 * ```
 */
export const TemplateMixin = (SuperClass) => class extends SuperClass {
    constructor() {
        super();
        let proto = this.constructor.prototype;
        if (proto.hasOwnProperty('template')) {
            let props = this.properties;
            if (props) {
                let callback = () => {
                    this.render();
                };
                for (let k in props) {
                    props[k].observe(callback);
                }
            }
        }
    }
    connectedCallback() {
        super.connectedCallback();
        let proto = this.constructor.prototype;
        if (proto.hasOwnProperty('template')) {
            this.render();
        }
    }
    /**
     * Update Component child nodes.
     */
    render(tpl) {
        tpl = tpl || this.template;
        /* istanbul ignore else */
        if (isFunction(tpl)) {
            tpl();
        } else if (isString(tpl)) {
            this.innerHTML = tpl;
        } else {
            throw new Error('Invalid template property.');
        }
    }
};
<commit_msg>fix: template property check<commit_after>import { isFunction, isString } from '../lib/typeof.js';

/**
 * Simple Custom Component with template handling using the `template` property.
 *
 * @example
 * my-component.js
 * ```js
 * import { Component, TemplateMixin, mix } from 'dna/component';
 * export class MyComponent extends mix(Component).with(TemplateMixin) {
 *   get template() {
 *     return '<h1>${this.name}</h1>';
 *   }
 *   get name() {
 *     return 'Newton';
 *   }
 * }
 * ```
 * app.js
 * ```js
 * import { define } from 'dna/component';
 * import { MyComponent } from './components/my-component/my-component.js';
 * define('my-component', MyComponent);
 * var element = new MyComponent();
 * console.log(element.innerHTML); // logs "<h1>Newton</h1>"
 * ```
 */
export const TemplateMixin = (SuperClass) => class extends SuperClass {
    constructor() {
        super();
        if (this.template) {
            let props = this.properties;
            if (props) {
                let callback = () => {
                    this.render();
                };
                for (let k in props) {
                    props[k].observe(callback);
                }
            }
        }
    }
    connectedCallback() {
        super.connectedCallback();
        let proto = this.constructor.prototype;
        if (this.template) {
            this.render();
        }
    }
    /**
     * Update Component child nodes.
     */
    render(tpl) {
        tpl = tpl || this.template;
        /* istanbul ignore else */
        if (isFunction(tpl)) {
            tpl();
        } else if (isString(tpl)) {
            this.innerHTML = tpl;
        } else {
            throw new Error('Invalid template property.');
        }
    }
};

{'fraction_non_alphanumeric': 0.14797202797202796, 'fraction_numerical': 0.0022377622377622378, 'mean_word_length': 1.8745980707395498, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2396701', 'n_tokens_mistral': 1006, 'n_tokens_neox': 1007, 'n_words': 234}