Skip to content

Commit 9ae2a68

Browse files
committed
Clean up codebase with regards to deprecated API
Ensure that deprecated Action & SModel API is encapsulated and do not leak into non-deprecated API by - Migrating the examples to the new Action/SModel API - Migrating the test cases to the new Action/SModel API - Remove any remaining usage of deprecated Action/SModel API in the non-deprecated code base In addition, this change restructures all files that contain deprecated Action/SModel API and moves the deprecated definitions in a separate section on the end of the file. This enables easy removal of the deprecated API with the 1.0.0 release. The deprecation section at the file end can be safely removed without breaking codebase.
1 parent e058bb2 commit 9ae2a68

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1547
-1452
lines changed

examples/circlegraph/src/standalone.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
********************************************************************************/
1616

1717
import {
18-
TYPES, IActionDispatcher, ElementMove, MoveAction, LocalModelSource
18+
TYPES, IActionDispatcher, ElementMove, LocalModelSource
1919
} from 'sprotty';
20-
import { Bounds, Point, SEdge, SelectAction, SGraph, SNode, getBasicType } from 'sprotty-protocol';
20+
import { Bounds, Point, SEdge, SelectAction, SGraph, SNode, getBasicType, MoveAction } from 'sprotty-protocol';
2121
import createContainer from './di.config';
2222

2323
const NODE_SIZE = 60;

examples/classdiagram/src/menu.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616

1717
import { inject, injectable } from 'inversify';
1818
import {
19-
Anchor, DeleteElementAction, EMPTY_ROOT, GetSelectionAction, IActionDispatcher,
19+
Anchor, EMPTY_ROOT, GetSelectionAction, IActionDispatcher,
2020
IContextMenuItemProvider, IContextMenuService, LabeledAction, MenuItem,
2121
RequestExportSvgAction, SelectionResult, SModelRootImpl, TYPES, ViewerOptions
2222
} from 'sprotty';
23-
import { CenterAction, FitToScreenAction, Point, SetPopupModelAction } from 'sprotty-protocol';
23+
import { CenterAction, DeleteElementAction, FitToScreenAction, Point, SetPopupModelAction } from 'sprotty-protocol';
2424

2525
@injectable()
2626
export class ClassContextMenuService implements IContextMenuService {

examples/svg/src/standalone.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
********************************************************************************/
1616

1717
import {
18-
TYPES, ShapedPreRenderedElementSchema, ForeignObjectElementSchema, SShapeElementSchema, ViewportRootElementSchema,
19-
Projectable, LocalModelSource
18+
TYPES, ViewportRootElementSchema, Projectable, LocalModelSource
2019
} from 'sprotty';
2120
import createContainer from './di.config';
21+
import { ForeignObjectElement, SShapeElement, ShapedPreRenderedElement } from 'sprotty-protocol';
2222

2323
function loadFile(path: string): Promise<string> {
2424
return new Promise<string>((resolve, reject) => {
@@ -50,21 +50,21 @@ export default async function runSVG() {
5050
position: { x: 200, y: 200 },
5151
code: svgLogo,
5252
projectionCssClasses: ['logo-projection']
53-
} as ShapedPreRenderedElementSchema & Projectable,
53+
} as ShapedPreRenderedElement & Projectable,
5454
{
5555
type: 'pre-rendered',
5656
id: 'tiger',
5757
position: { x: 400, y: 50 },
5858
code: tiger,
5959
projectionCssClasses: ['tiger-projection']
60-
} as ShapedPreRenderedElementSchema & Projectable,
60+
} as ShapedPreRenderedElement & Projectable,
6161
{
6262
type: 'foreign-object',
6363
id: 'direct-html',
6464
position: { x: 50, y: 350 },
6565
size: { height: 50, width: 190 },
6666
code: '<p>This is a free-floating HTML paragraph!</p>'
67-
} as ForeignObjectElementSchema,
67+
} as ForeignObjectElement,
6868
{
6969
id: 'foreign-object-in-shape',
7070
type: 'node',
@@ -81,10 +81,10 @@ export default async function runSVG() {
8181
type: 'child-foreign-object',
8282
id: 'foreign-object-in-shape-contents',
8383
code: '<div>This is <em>HTML</em> within <u>an SVG rectangle</u>!</div>'
84-
} as ForeignObjectElementSchema
84+
} as ForeignObjectElement
8585
],
8686
projectionCssClasses: ['node-projection']
87-
} as SShapeElementSchema & Projectable
87+
} as SShapeElement & Projectable
8888
]
8989
};
9090

packages/sprotty/src/base/actions/action-dispatcher.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ import 'reflect-metadata';
1818
import 'mocha';
1919
import { expect } from "chai";
2020
import { Container, injectable, interfaces } from "inversify";
21-
import { Action, RejectAction, RequestModelAction, SetModelAction } from 'sprotty-protocol/lib/actions';
21+
import { Action, RedoAction, RejectAction, RequestModelAction, SetModelAction, UndoAction } from 'sprotty-protocol/lib/actions';
2222
import { Bounds } from 'sprotty-protocol/lib/utils/geometry';
2323
import { TYPES } from "../types";
2424
import { InitializeCanvasBoundsAction } from '../features/initialize-canvas';
25-
import { RedoAction, UndoAction } from "../../features/undo-redo/undo-redo";
2625
import { Command, CommandExecutionContext, CommandReturn, ICommand } from '../commands/command';
2726
import { ICommandStack } from "../commands/command-stack";
2827
import { ActionDispatcher } from "./action-dispatcher";

packages/sprotty/src/base/actions/action.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@ import { generateRequestId as generateRequestId2, Action as ProtocolAction} from
1818
import { JsonAny } from 'sprotty-protocol/lib/utils/json';
1919
import { hasOwnProperty } from 'sprotty-protocol/lib/utils/object';
2020

21+
/**
22+
* A list of actions with a label.
23+
* Labeled actions are used to denote a group of actions in a user-interface context, e.g.,
24+
* to define an entry in the command palette or in the context menu.
25+
*/
26+
export class LabeledAction {
27+
constructor(readonly label: string, readonly actions: ProtocolAction[], readonly icon?: string) { }
28+
}
29+
30+
export function isLabeledAction(element: unknown): element is LabeledAction {
31+
return element !== undefined
32+
&& (<LabeledAction>element).label !== undefined
33+
&& (<LabeledAction>element).actions !== undefined;
34+
}
35+
36+
// Compatibility deprecation layer (will be removed with the graduation 1.0.0 release)
37+
2138
/**
2239
* An action describes a change to the model declaratively.
2340
* It is a plain data structure, and as such transferable between server and client. An action must never contain actual
@@ -93,17 +110,3 @@ export class RejectAction implements ResponseAction {
93110
public readonly detail?: JsonAny) {}
94111
}
95112

96-
/**
97-
* A list of actions with a label.
98-
* Labeled actions are used to denote a group of actions in a user-interface context, e.g.,
99-
* to define an entry in the command palette or in the context menu.
100-
*/
101-
export class LabeledAction {
102-
constructor(readonly label: string, readonly actions: ProtocolAction[], readonly icon?: string) { }
103-
}
104-
105-
export function isLabeledAction(element: unknown): element is LabeledAction {
106-
return element !== undefined
107-
&& (<LabeledAction>element).label !== undefined
108-
&& (<LabeledAction>element).actions !== undefined;
109-
}

packages/sprotty/src/base/commands/command-registration.spec.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,18 @@ import { expect } from "chai";
2020
import { Container, injectable, inject } from "inversify";
2121
import { TYPES } from "../types";
2222
import { configureCommand, CommandActionHandlerInitializer } from "./command-registration";
23-
import { SetModelCommand, SetModelAction } from "../features/set-model";
23+
import { SetModelCommand } from "../features/set-model";
2424
import { ActionHandlerRegistry } from "../actions/action-handler";
2525
import { EMPTY_ROOT } from "../model/smodel-factory";
2626
import { Command, CommandResult } from "./command";
27+
import { SetModelAction } from "sprotty-protocol";
2728

2829
const MySymbol = Symbol('MySymbol');
2930

3031
class MyAction {
3132
kind = MyCommand.KIND;
3233

33-
constructor(readonly value: string) {}
34+
constructor(readonly value: string) { }
3435
}
3536

3637
@injectable()
@@ -49,13 +50,13 @@ class MyCommand extends Command {
4950
}
5051

5152
describe('CommandRegistration', () => {
52-
it ('creates new instances', () => {
53+
it('creates new instances', () => {
5354
const container = new Container();
5455
container.bind(TYPES.IActionHandlerInitializer).to(CommandActionHandlerInitializer).inSingletonScope();
5556
container.bind(ActionHandlerRegistry).toSelf().inSingletonScope();
5657
configureCommand(container, SetModelCommand);
5758
const actionHandlerRegistry = container.get<ActionHandlerRegistry>(ActionHandlerRegistry);
58-
const action = new SetModelAction(EMPTY_ROOT);
59+
const action = SetModelAction.create(EMPTY_ROOT);
5960
const handlers = actionHandlerRegistry.get(action.kind);
6061
expect(handlers.length).to.be.equal(1);
6162
const handler = handlers.pop()!;
@@ -64,13 +65,13 @@ describe('CommandRegistration', () => {
6465
const command1 = handler.handle(action);
6566
expect(command1).to.be.an.instanceOf(SetModelCommand);
6667
expect(command0).to.not.be.equal(command1);
67-
const command2 = handler.handle(new SetModelAction({ type: 'other', id: '0' }));
68+
const command2 = handler.handle(SetModelAction.create({ type: 'other', id: '0' }));
6869
expect(command2).to.be.an.instanceOf(SetModelCommand);
6970
expect(command2).to.not.be.equal(command1);
7071
expect(command2).to.not.be.equal(command0);
7172
});
7273

73-
it ('injects members', () => {
74+
it('injects members', () => {
7475
const container = new Container();
7576
container.bind(TYPES.IActionHandlerInitializer).to(CommandActionHandlerInitializer).inSingletonScope();
7677
container.bind(ActionHandlerRegistry).toSelf().inSingletonScope();

packages/sprotty/src/base/features/initialize-canvas.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
import "reflect-metadata";
1818
import "mocha";
1919
import { expect } from "chai";
20-
import { Bounds, EMPTY_BOUNDS } from '../../utils/geometry';
21-
import { SModelRoot } from "../model/smodel";
2220
import { CommandExecutionContext } from '../commands/command';
2321
import { InitializeCanvasBoundsAction, InitializeCanvasBoundsCommand } from './initialize-canvas';
22+
import { SModelRootImpl } from "../model/smodel";
23+
import { Bounds } from "sprotty-protocol";
2424

2525
describe('InitializeCanvasBoundsCommand', () => {
2626

@@ -31,7 +31,7 @@ describe('InitializeCanvasBoundsCommand', () => {
3131
height: 10
3232
};
3333

34-
const root = new SModelRoot();
34+
const root = new SModelRootImpl();
3535
const command = new InitializeCanvasBoundsCommand(InitializeCanvasBoundsAction.create(bounds));
3636

3737
const context: CommandExecutionContext = {
@@ -45,7 +45,7 @@ describe('InitializeCanvasBoundsCommand', () => {
4545

4646
it('execute() works as expected', () => {
4747
// sanity check for initial bounds values
48-
expect(EMPTY_BOUNDS).deep.equals(root.canvasBounds);
48+
expect(Bounds.EMPTY).deep.equals(root.canvasBounds);
4949
command.execute(context);
5050
expect(bounds).deep.equals(root.canvasBounds);
5151
});

packages/sprotty/src/base/features/set-model.spec.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@ import 'mocha';
1919
import { expect } from "chai";
2020
import { Container } from 'inversify';
2121
import { TYPES } from '../types';
22-
import { SModelElement, SModelElementSchema, SModelRootSchema } from "../model/smodel";
22+
import { SModelElementImpl } from "../model/smodel";
2323
import { EMPTY_ROOT } from '../model/smodel-factory';
2424
import { SGraphFactory } from "../../graph/sgraph-factory";
2525
import { CommandExecutionContext } from "../commands/command";
2626
import { ConsoleLogger } from "../../utils/logging";
2727
import { AnimationFrameSyncer } from "../animations/animation-frame-syncer";
28-
import { SetModelAction, SetModelCommand } from "./set-model";
28+
import { SetModelCommand } from "./set-model";
2929
import defaultModule from "../di.config";
30+
import { SModelElement, SModelRoot, SetModelAction } from 'sprotty-protocol';
3031

31-
function compare(expected: SModelElementSchema, actual: SModelElement) {
32+
function compare(expected: SModelElement, actual: SModelElementImpl) {
3233
for (const p in expected) {
3334
if (expected.hasOwnProperty(p)) {
3435
const expectedProp = (expected as any)[p];
@@ -70,14 +71,14 @@ describe('SetModelCommand', () => {
7071
children: []
7172
});
7273

73-
const model2: SModelRootSchema = {
74+
const model2: SModelRoot = {
7475
id: 'model2',
7576
type: 'graph',
7677
children: []
7778
};
7879

7980
// create the action
80-
const mySetModelAction = new SetModelAction(model2 /* the new model */);
81+
const mySetModelAction = SetModelAction.create(model2 /* the new model */);
8182

8283
// create the command
8384
const cmd = new SetModelCommand(mySetModelAction);

packages/sprotty/src/base/features/set-model.ts

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,38 @@ import { SModelRootImpl } from "../model/smodel";
2626
import { TYPES } from "../types";
2727
import { InitializeCanvasBoundsCommand } from './initialize-canvas';
2828

29+
@injectable()
30+
export class SetModelCommand extends ResetCommand {
31+
static readonly KIND = ProtocolSetModelAction.KIND;
32+
33+
oldRoot: SModelRootImpl;
34+
newRoot: SModelRootImpl;
35+
36+
constructor(@inject(TYPES.Action) protected readonly action: ProtocolSetModelAction) {
37+
super();
38+
}
39+
40+
execute(context: CommandExecutionContext): SModelRootImpl {
41+
this.oldRoot = context.modelFactory.createRoot(context.root);
42+
this.newRoot = context.modelFactory.createRoot(this.action.newRoot);
43+
return this.newRoot;
44+
}
45+
46+
undo(context: CommandExecutionContext): SModelRootImpl {
47+
return this.oldRoot;
48+
}
49+
50+
redo(context: CommandExecutionContext): SModelRootImpl {
51+
return this.newRoot;
52+
}
53+
54+
get blockUntil(): (action: Action) => boolean {
55+
return action => action.kind === InitializeCanvasBoundsCommand.KIND;
56+
}
57+
}
58+
59+
// Compatibility deprecation layer (will be removed with the graduation 1.0.0 release)
60+
2961
/**
3062
* Sent from the client to the model source (e.g. a DiagramServer) in order to request a model. Usually this
3163
* is the first message that is sent to the source, so it is also used to initiate the communication.
@@ -58,33 +90,3 @@ export class SetModelAction implements ResponseAction, ProtocolSetModelAction {
5890
constructor(public readonly newRoot: SModelRootSchema,
5991
public readonly responseId = '') { }
6092
}
61-
62-
@injectable()
63-
export class SetModelCommand extends ResetCommand {
64-
static readonly KIND = ProtocolSetModelAction.KIND;
65-
66-
oldRoot: SModelRootImpl;
67-
newRoot: SModelRootImpl;
68-
69-
constructor(@inject(TYPES.Action) protected readonly action: ProtocolSetModelAction) {
70-
super();
71-
}
72-
73-
execute(context: CommandExecutionContext): SModelRootImpl {
74-
this.oldRoot = context.modelFactory.createRoot(context.root);
75-
this.newRoot = context.modelFactory.createRoot(this.action.newRoot);
76-
return this.newRoot;
77-
}
78-
79-
undo(context: CommandExecutionContext): SModelRootImpl {
80-
return this.oldRoot;
81-
}
82-
83-
redo(context: CommandExecutionContext): SModelRootImpl {
84-
return this.newRoot;
85-
}
86-
87-
get blockUntil(): (action: Action) => boolean {
88-
return action => action.kind === InitializeCanvasBoundsCommand.KIND;
89-
}
90-
}

packages/sprotty/src/base/model/smodel-factory.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,18 @@ import 'mocha';
1919
import { expect } from "chai";
2020
import { Container } from 'inversify';
2121
import { TYPES } from '../types';
22-
import { SModelElementSchema, ModelIndexImpl, SChildElement } from './smodel';
22+
import { ModelIndexImpl, SChildElementImpl } from './smodel';
2323
import { SModelFactory } from "./smodel-factory";
2424
import { registerModelElement } from './smodel-utils';
2525
import { selectFeature, Selectable } from '../../features/select/model';
2626
import { boundsFeature } from '../../features/bounds/model';
2727
import defaultModule from "../di.config";
28+
import { SModelElement } from 'sprotty-protocol';
2829

2930
describe('model factory', () => {
3031

31-
class FooElement extends SChildElement implements Selectable {
32-
static readonly DEFAULT_FEATURES = [selectFeature]
32+
class FooElement extends SChildElementImpl implements Selectable {
33+
static readonly DEFAULT_FEATURES = [selectFeature];
3334
selected: boolean;
3435
}
3536

@@ -67,7 +68,7 @@ describe('model factory', () => {
6768
id: 'element3'
6869
}
6970
]
70-
} as SModelElementSchema
71+
} as SModelElement
7172
]
7273
});
7374
const element1 = root.children[0];

0 commit comments

Comments
 (0)