Skip to content

Latest commit

 

History

History
65 lines (49 loc) · 1.07 KB

File metadata and controls

65 lines (49 loc) · 1.07 KB

## TODO

  • datalabel system with click switch.

  • zoom limits

ChartHTML

  • get tests from ChartHTML ?
  • Update ChartHTML

Clean

  • fix parent (?).
  • use WeakRef array (cf below)
  • use asserts...
  • move merge into WebMisc...
class WeakRefArray {
  #refs = [];

  add(object) {
    if (typeof object !== 'object' || object === null) {
      throw new TypeError('WeakRefArray only supports non-null objects.');
    }
    this.#refs.push(new WeakRef(object));
  }

  cleanup() {
    this.#refs = this.#refs.filter(ref => ref.deref() !== undefined);
  }

  forEach(callback) {
    let hasDeadRef = false;

    for (const ref of this.#refs) {
      const value = ref.deref();

      if (value === undefined) {
        hasDeadRef = true;
        continue;
      }

      callback(value);
    }

    if (hasDeadRef) {
      this.cleanup();
    }
  }

  size() {
    this.cleanup();
    return this.#refs.length;
  }

  [Symbol.iterator]() {
    this.cleanup();
    return this.#refs
      .map(ref => ref.deref()) // Toutes sont vivantes après cleanup()
      [Symbol.iterator]();
  }
}