import type { ValidEntity, EntityType } from "./Entity/index.js"; import type { IResourceController } from "./IResourceController.js"; export abstract class LazyEntityUpdater{ protected abstract readonly _indirectNames: ReadonlyArray; protected abstract readonly _entityType: EntityType; protected abstract readonly _raw: Entity; protected abstract readonly rsc: IResourceController; public get raw(): Readonly { return this._raw; } public get entityType(): EntityType { return this._entityType; } protected forceUpdate(callback: (raw: Entity) => void) { callback(this._raw); this.rsc.reserveUpdate(this); } public update(callback: (raw: Entity) => void) { const oldRaw = { ...this._raw }; callback(this._raw); //for구문이 빠른가, Proxy setter로 제어하는게 빠른가 for (const indirectName of this._indirectNames) { if (oldRaw[indirectName] !== this._raw[indirectName]) { throw new Error(`${String(indirectName)} change by update() is not allowed`); } } this.rsc.reserveUpdate(this); } }