Skip to content

Commit 385269d

Browse files
authored
Ensure that recording commands can be executed asychronous (#40)
Change signature of `applyPatch` and `getJsonObject` to allso allow promise return values Also: add missing exports to main index
1 parent 44aae0c commit 385269d

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

packages/server/src/common/command/recording-command.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ export abstract class AbstractRecordingCommand<JsonObject extends AnyObject> imp
2929
protected redoPatch?: jsonPatch.Operation[];
3030

3131
async execute(): Promise<void> {
32-
const beforeState = this.deepClone(this.getJsonObject());
32+
const beforeState = this.deepClone(await this.getJsonObject());
3333
await this.doExecute();
34-
const afterState = this.getJsonObject();
34+
const afterState = await this.getJsonObject();
3535
this.undoPatch = jsonPatch.compare(afterState, beforeState);
3636
this.redoPatch = jsonPatch.compare(beforeState, afterState);
3737
}
@@ -41,14 +41,14 @@ export abstract class AbstractRecordingCommand<JsonObject extends AnyObject> imp
4141
* right after {@link AbstractRecordingCommand.doExecute} to derive the undo & redo patches.
4242
* @returns The current state of the JSON object
4343
*/
44-
protected abstract getJsonObject(): JsonObject;
44+
protected abstract getJsonObject(): MaybePromise<JsonObject>;
4545

4646
/**
4747
* The actual execution i.e. series of changes applied to the JSOn object that should be captured.
4848
*/
4949
protected abstract doExecute(): MaybePromise<void>;
5050

51-
protected applyPatch(object: JsonObject, patch: jsonPatch.Operation[]): void {
51+
protected applyPatch(object: JsonObject, patch: jsonPatch.Operation[]): MaybePromise<void> {
5252
jsonPatch.applyPatch(object, patch, false, true);
5353
}
5454

@@ -62,15 +62,15 @@ export abstract class AbstractRecordingCommand<JsonObject extends AnyObject> imp
6262
return jsonPatch.deepClone(object);
6363
}
6464

65-
undo(): void {
65+
async undo(): Promise<void> {
6666
if (this.undoPatch) {
67-
this.applyPatch(this.getJsonObject(), this.undoPatch);
67+
return this.applyPatch(await this.getJsonObject(), this.undoPatch);
6868
}
6969
}
7070

71-
redo(): void {
71+
async redo(): Promise<void> {
7272
if (this.redoPatch) {
73-
this.applyPatch(this.getJsonObject(), this.redoPatch);
73+
return this.applyPatch(await this.getJsonObject(), this.redoPatch);
7474
}
7575
}
7676

@@ -88,7 +88,7 @@ export class RecordingCommand<JsonObject extends AnyObject = AnyObject> extends
8888
super();
8989
}
9090

91-
protected getJsonObject(): JsonObject {
91+
protected getJsonObject(): MaybePromise<JsonObject> {
9292
return this.jsonObject;
9393
}
9494
}
@@ -107,11 +107,11 @@ export class GModelRecordingCommand extends AbstractRecordingCommand<GModelRootS
107107
this.modelState.index.indexRoot(this.modelState.root);
108108
}
109109

110-
protected getJsonObject(): GModelRootSchema {
110+
protected getJsonObject(): MaybePromise<GModelRootSchema> {
111111
return this.serializer.createSchema(this.modelState.root);
112112
}
113113

114-
protected override applyPatch(rootSchema: GModelRootSchema, patch: jsonPatch.Operation[]): void {
114+
protected override applyPatch(rootSchema: GModelRootSchema, patch: jsonPatch.Operation[]): MaybePromise<void> {
115115
super.applyPatch(rootSchema, patch);
116116
const newRoot = this.serializer.createRoot(rootSchema);
117117
this.modelState.updateRoot(newRoot);

packages/server/src/common/features/layout/computed-bounds-action-handler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { GModelRoot } from '@eclipse-glsp/graph';
1717
import { Action, ComputedBoundsAction, MaybePromise } from '@eclipse-glsp/protocol';
1818
import { inject, injectable } from 'inversify';
1919
import { ActionHandler } from '../../actions/action-handler';
20-
import { applyAlignment, applyBounds, applyRoute } from '../../utils/layout-util';
20+
import { applyAlignment, applyElementAndBounds, applyRoute } from '../../utils/layout-util';
2121
import { ModelState } from '../model/model-state';
2222
import { ModelSubmissionHandler } from '../model/model-submission-handler';
2323

@@ -47,7 +47,7 @@ export class ComputedBoundsActionHandler implements ActionHandler {
4747

4848
protected applyBounds(root: GModelRoot, action: ComputedBoundsAction): void {
4949
const index = this.modelState.index;
50-
action.bounds.forEach(bounds => applyBounds(bounds, index));
50+
action.bounds.forEach(bounds => applyElementAndBounds(bounds, index));
5151
(action.alignments ?? []).forEach(alignment => applyAlignment(alignment, index));
5252
(action.routes ?? []).forEach(route => applyRoute(route, index));
5353
}

packages/server/src/common/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export * from './actions/client-action-handler';
2323
export * from './actions/global-action-provider';
2424
export * from './command/command';
2525
export * from './command/command-stack';
26+
export * from './command/recording-command';
27+
export * from './command/undo-redo-action-handler';
2628
export * from './di/binding-target';
2729
export * from './di/client-session-module';
2830
export * from './di/diagram-module';
@@ -65,7 +67,6 @@ export * from './features/popup/popup-model-factory';
6567
export * from './features/popup/request-popup-model-action-handler';
6668
export * from './features/validation/model-validator';
6769
export * from './features/validation/request-markers-handler';
68-
export * from './gmodel/cut-operation-handler';
6970
export * from './gmodel/index';
7071
export * from './launch/glsp-server-launcher';
7172
export * from './operations/compound-operation-handler';
@@ -84,6 +85,7 @@ export * from './session/client-session-manager';
8485
export * from './utils/args-util';
8586
export * from './utils/client-options-util';
8687
export * from './utils/glsp-server-error';
88+
export * from './utils/layout-util';
8789
export * from './utils/logger';
8890
export * from './utils/promise-queue';
8991
export * from './utils/registry';

packages/server/src/common/utils/layout-util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { getOrThrow, GLSPServerError } from './glsp-server-error';
2727
* @param index The model index.
2828
* @returns The changed element.
2929
*/
30-
export function applyBounds(bounds: ElementAndBounds, index: GModelIndex): GBoundsAware | undefined {
30+
export function applyElementAndBounds(bounds: ElementAndBounds, index: GModelIndex): GBoundsAware | undefined {
3131
const element = getOrThrow(index.get(bounds.elementId), 'Model element not found! ID: ' + bounds.elementId);
3232
if (isGBoundsAware(element)) {
3333
if (bounds.newPosition !== undefined) {

0 commit comments

Comments
 (0)