all files / gluebert/src/module/ module.signature.js

47.06% Statements 8/17
100% Branches 1/1
33.33% Functions 3/9
47.06% Lines 8/17
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100                                                                                                                                                                                       
/**
 * Class representing ModuleSignature
 */
class ModuleSignature {
 
    /**
     * creates new ModuleSignature object
     * @param {string} name - Module name
     * @param {string|null} selector
     */
    constructor(name, selector = null) {
        this.name = name;
        this.selector = selector;
        this.importController = null;
        this.importStyles = null;
        this.elements = new Set();
    }
 
    /**
     * set controller selector
     * @param {string} selector - selector for document.querySelectorAll()
     * @example new ModuleSignature('example').setSelector('.example-class-selector')
     * @return {ModuleSignature}
     */
    setSelector(selector) {
        this.selector = selector;
        return this;
    }
 
 
    /**
     * get defined selector
     * @return {string|null}
     */
    getSelector() {
        return this.selector;
    }
 
    /**
     * set controller import
     * @param {function} controller
     * @example
     * new ModuleSignature('example')
     *  .setModuleImport(() => import('./example.controller'));
     * @return {AbstractController}
     */
    setControllerImport(controller) {
        this.importController = controller;
        return this;
    }
 
    /**
     * get controller import method
     * @return {function|null}
     */
    getControllerImport() {
        return this.importController;
    }
 
    /**
     * set styles import
     * @param {function} styles
     * @return {ModuleSignature}
     */
    setStylesImport(styles) {
        this.importStyles = styles;
        return this;
    }
 
    /**
     * get styles import method
     * @return {function|null}
     */
    getStylesImport() {
        return this.importStyles;
    }
 
    /**
     * add element signature
     * @param {ElementSignature} elementSignature
     * @return {ModuleSignature}
     */
    addElementSignature(elementSignature) {
        this.elements.add(elementSignature);
        return this;
    }
 
    /**
     * get elements signatures
     * @return {Set} - set of ElementSignature
     */
    getElementSignatures() {
        return this.elements;
    }
 
}
 
export {
    ModuleSignature,
};