tidy(ui): consolidate getLoggingContext builders

This commit is contained in:
psychedelicious 2024-08-02 13:26:28 +10:00
parent 8e1a70b008
commit ad9312e989
8 changed files with 31 additions and 24 deletions

View File

@ -30,7 +30,7 @@ export class CanvasBrushLine {
this.parent = parent;
this.manager = parent.manager;
this.getLoggingContext = this.manager.buildObjectGetLoggingContext(this);
this.getLoggingContext = this.manager.buildGetLoggingContext(this);
this.log = this.manager.buildLogger(this.getLoggingContext);
this.log.trace({ state }, 'Creating brush line');

View File

@ -29,7 +29,7 @@ export class CanvasEraserLine {
this.id = id;
this.parent = parent;
this.manager = parent.manager;
this.getLoggingContext = this.manager.buildObjectGetLoggingContext(this);
this.getLoggingContext = this.manager.buildGetLoggingContext(this);
this.log = this.manager.buildLogger(this.getLoggingContext);
this.log.trace({ state }, 'Creating eraser line');

View File

@ -39,7 +39,7 @@ export class CanvasImage {
this.id = id;
this.parent = parent;
this.manager = parent.manager;
this.getLoggingContext = this.manager.buildObjectGetLoggingContext(this);
this.getLoggingContext = this.manager.buildGetLoggingContext(this);
this.log = this.manager.buildLogger(this.getLoggingContext);
this.log.trace({ state }, 'Creating image');

View File

@ -60,7 +60,7 @@ export class CanvasLayer {
constructor(state: LayerEntity, manager: CanvasManager) {
this.id = state.id;
this.manager = manager;
this.getLoggingContext = this.manager.buildEntityGetLoggingContext(this);
this.getLoggingContext = this.manager.buildGetLoggingContext(this);
this.log = this.manager.buildLogger(this.getLoggingContext);
this.log.debug({ state }, 'Creating layer');

View File

@ -591,26 +591,33 @@ export class CanvasManager {
});
}
buildObjectGetLoggingContext = (
instance: CanvasBrushLine | CanvasEraserLine | CanvasRect | CanvasImage | CanvasTransformer
buildGetLoggingContext = (
instance:
| CanvasBrushLine
| CanvasEraserLine
| CanvasRect
| CanvasImage
| CanvasTransformer
| CanvasLayer
| CanvasStagingArea
): GetLoggingContext => {
return (extra?: JSONObject): JSONObject => {
return {
...instance.parent.getLoggingContext(),
objectId: instance.id,
...extra,
if (instance instanceof CanvasLayer || instance instanceof CanvasStagingArea) {
return (extra?: JSONObject): JSONObject => {
return {
...instance.manager.getLoggingContext(),
entityId: instance.id,
...extra,
};
};
};
};
buildEntityGetLoggingContext = (instance: CanvasLayer | CanvasStagingArea): GetLoggingContext => {
return (extra?: JSONObject): JSONObject => {
return {
...instance.manager.getLoggingContext(),
entityId: instance.id,
...extra,
} else {
return (extra?: JSONObject): JSONObject => {
return {
...instance.parent.getLoggingContext(),
objectId: instance.id,
...extra,
};
};
};
}
};
logDebugInfo() {

View File

@ -28,7 +28,7 @@ export class CanvasRect {
this.id = id;
this.parent = parent;
this.manager = parent.manager;
this.getLoggingContext = this.manager.buildObjectGetLoggingContext(this);
this.getLoggingContext = this.manager.buildGetLoggingContext(this);
this.log = this.manager.buildLogger(this.getLoggingContext);
this.log.trace({ state }, 'Creating rect');

View File

@ -22,7 +22,7 @@ export class CanvasStagingArea {
constructor(manager: CanvasManager) {
this.id = getPrefixedId(CanvasStagingArea.TYPE);
this.manager = manager;
this.getLoggingContext = this.manager.buildEntityGetLoggingContext(this);
this.getLoggingContext = this.manager.buildGetLoggingContext(this);
this.log = this.manager.buildLogger(this.getLoggingContext);
this.log.debug('Creating staging area');

View File

@ -63,7 +63,7 @@ export class CanvasTransformer {
this.manager = parent.manager;
this.transformTarget = transformTarget;
this.getLoggingContext = this.manager.buildObjectGetLoggingContext(this);
this.getLoggingContext = this.manager.buildGetLoggingContext(this);
this.log = this.manager.buildLogger(this.getLoggingContext);
this.subscriptions = [];