All files / lib/core/reactive createComputed.js

95.65% Statements 44/46
83.33% Branches 5/6
80% Functions 4/5
95.65% Lines 44/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 47627x 627x 627x 627x 627x 627x 627x 627x 877x 877x 877x 627x 627x 627x 627x 627x 627x 1390x 1390x 627x 627x 627x 627x 627x 627x 627x 41x 41x 627x 627x 627x 627x 627x 627x 627x 59x 59x 627x 627x 627x 627x 627x 627x     627x  
/**
 * 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;
  }
}