All files / lib/core/reactive createComputed.js

91.3% Statements 42/46
80% Branches 4/5
60% Functions 3/5
91.3% Lines 42/46

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 46 4711x 11x 11x 11x 11x 11x 11x 11x 19x 19x 19x 11x 11x 11x 11x 11x 11x 19x 19x 11x 11x 11x 11x 11x 11x 11x     11x 11x 11x 11x 11x 11x 11x 1x 1x 11x 11x 11x 11x 11x 11x     11x  
/**
 * Registry for computed property definitions.
 */
export class ComputedRegistry {
    /**
     * @param {Object} [computed={}] - An object containing computed property definitions (expressions).
     */
    constructor(computed = {}) {
        /** @type {Object} */
        this.computed = computed || {};
    }
 
    /**
     * Returns the keys of all registered computed properties.
     * @returns {string[]}
     */
    keys() {
        return Object.keys(this.computed);
    }
 
    /**
     * Checks if a computed property with the given key exists.
     * @param {string} key - The key to check.
     * @returns {boolean}
     */
    has(key) {
        return Object.prototype.hasOwnProperty.call(this.computed, key);
    }
 
    /**
     * Returns the expression for a given computed property key.
     * @param {string} key - The key to retrieve.
     * @returns {string|undefined}
     */
    get(key) {
        return this.computed[key];
    }
 
    /**
     * Returns all registered computed property definitions.
     * @returns {Object}
     */
    all() {
        return this.computed;
    }
}