structures/Base.js

/**
 * Represents a data model that is identifiable by a name
 */
class Base {
  constructor(thunderAPI) {
    /**
     * The instance of ThunderAPI that instantiated this
     * @name Base#thunderAPI
     * @type {ThunderAPI}
     * @readonly
     */
    Object.defineProperty(this, "thunderAPI", { value: thunderAPI });
  }

  _clone() {
    return Object.assign(Object.create(this), this);
  }

  _patch(data) { return data; }

  _update(data) {
    const clone = this._clone();
    this._patch(data);
    return clone;
  }

  valueOf() {
    return this.id;
  }
}

module.exports = Base;