refac: shorthand name. ResourceController > rsc

This commit is contained in:
2024-03-09 07:40:55 +00:00
parent a6833473de
commit a430d45e2a
6 changed files with 61 additions and 36 deletions
+14 -9
View File
@@ -1,5 +1,5 @@
import type { ValidEntity, EntityType } from "./Entity/index.js";
import type { IResourceController } from "./ResourceController.js";
import type { IResourceController } from "./IResourceController.js";
export abstract class LazyEntityUpdater<Entity extends ValidEntity>{
protected abstract readonly _indirectNames: ReadonlyArray<keyof Entity>;
@@ -7,7 +7,7 @@ export abstract class LazyEntityUpdater<Entity extends ValidEntity>{
protected abstract readonly _raw: Entity;
protected abstract readonly resourceController: IResourceController;
protected abstract readonly rsc: IResourceController;
public get raw(): Readonly<Entity> {
return this._raw;
@@ -17,16 +17,21 @@ export abstract class LazyEntityUpdater<Entity extends ValidEntity>{
return this._entityType;
}
public update(callback: (oldRaw: Entity) => void, force = false) {
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);
if (!force) {
for (const indirectName of this._indirectNames) {
if (oldRaw[indirectName] !== this._raw[indirectName]) {
throw new Error(`${String(indirectName)} change by update() is not allowed`);
}
//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.resourceController.reserveUpdate(this);
this.rsc.reserveUpdate(this);
}
}