Skip to content

Commit

Permalink
Removed deprecated API
Browse files Browse the repository at this point in the history
  • Loading branch information
spoenemann committed Sep 1, 2023
1 parent 3342e66 commit 5cefac4
Show file tree
Hide file tree
Showing 48 changed files with 366 additions and 2,323 deletions.
20 changes: 10 additions & 10 deletions examples/multicore/src/chipmodel-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import {
createFeatureSet, Direction
} from 'sprotty';
import {
SModelElement as SModelElementSchema, SModelRoot as SModelRootSchema, HtmlRoot as HtmlRootSchema,
PreRenderedElement as PreRenderedElementSchema, getBasicType
SModelElement, SModelRoot, HtmlRoot as HtmlRootSchema,
PreRenderedElement, getBasicType
} from 'sprotty-protocol';
import {
Channel, ChannelSchema, Core, CoreSchema, Crossbar, CrossbarSchema, Processor, ProcessorSchema
Expand All @@ -30,7 +30,7 @@ import { CORE_WIDTH, CORE_DISTANCE } from './views';

export class ChipModelFactory extends SGraphFactory {

override createElement(schema: SModelElementSchema, parent?: SParentElementImpl): SChildElementImpl {
override createElement(schema: SModelElement, parent?: SParentElementImpl): SChildElementImpl {
try {
if (this.isCoreSchema(schema)) {
this.validate(schema, parent);
Expand Down Expand Up @@ -59,7 +59,7 @@ export class ChipModelFactory extends SGraphFactory {
return super.createElement(schema, parent);
}

override createRoot(schema: SModelRootSchema): SModelRootImpl {
override createRoot(schema: SModelRoot): SModelRootImpl {
if (this.isProcessorSchema(schema)) {
const processor = this.initializeRoot(new Processor(), schema);
processor.features = createFeatureSet(Processor.DEFAULT_FEATURES);
Expand Down Expand Up @@ -94,28 +94,28 @@ export class ChipModelFactory extends SGraphFactory {
}
}

isProcessorSchema(schema: SModelElementSchema): schema is ProcessorSchema {
isProcessorSchema(schema: SModelElement): schema is ProcessorSchema {
return getBasicType(schema) === 'processor';
}

isCoreSchema(schema: SModelElementSchema): schema is CoreSchema {
isCoreSchema(schema: SModelElement): schema is CoreSchema {
const basicType = getBasicType(schema);
return basicType === 'core' || basicType === 'simplecore';
}

isChannelSchema(schema: SModelElementSchema): schema is ChannelSchema {
isChannelSchema(schema: SModelElement): schema is ChannelSchema {
return getBasicType(schema) === 'channel';
}

isCrossbarSchema(schema: SModelElementSchema): schema is CrossbarSchema {
isCrossbarSchema(schema: SModelElement): schema is CrossbarSchema {
return getBasicType(schema) === 'crossbar';
}

isHtmlRootSchema(schema: SModelElementSchema): schema is HtmlRootSchema {
isHtmlRootSchema(schema: SModelElement): schema is HtmlRootSchema {
return getBasicType(schema) === 'html';
}

isPreRenderedSchema(schema: SModelElementSchema): schema is PreRenderedElementSchema {
isPreRenderedSchema(schema: SModelElement): schema is PreRenderedElement {
return getBasicType(schema) === 'pre-rendered';
}
}
27 changes: 1 addition & 26 deletions packages/sprotty-elk/src/elk-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
********************************************************************************/

import {
ELK, ElkNode, ElkGraphElement, ElkLabel, ElkPort, ElkShape, ElkExtendedEdge, LayoutOptions, ElkPrimitiveEdge
ELK, ElkNode, ElkLabel, ElkPort, ElkShape, ElkExtendedEdge, LayoutOptions, ElkPrimitiveEdge
} from 'elkjs/lib/elk-api';
import { IModelLayoutEngine } from 'sprotty-protocol/lib/diagram-services';
import { SCompartment, SEdge, SGraph, SLabel, SModelElement, SNode, SPort, SShapeElement } from 'sprotty-protocol/lib/model';
Expand Down Expand Up @@ -84,31 +84,6 @@ export class ElkLayoutEngine implements IModelLayoutEngine {
return getBasicType(smodel);
}

/**
* @deprecated Use the more specialized transform methods instead.
*/
protected transformToElk(smodel: SModelElement, index: SModelIndex): ElkGraphElement {
switch (this.getBasicType(smodel)) {
case 'graph':
return this.transformGraph(smodel as SGraph, index);

case 'node':
return this.transformNode(smodel as SNode, index);

case 'edge':
return this.transformEdge(smodel as SEdge, index);

case 'label':
return this.transformLabel(smodel as SLabel, index);

case 'port':
return this.transformPort(smodel as SPort, index);

default:
throw new Error('Type not supported: ' + smodel.type);
}
}

/**
* Transform a Sprotty graph element to an ELK graph element.
*/
Expand Down
21 changes: 1 addition & 20 deletions packages/sprotty-protocol/src/diagram-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { ServerActionHandler, ServerActionHandlerRegistry } from './action-handler';
import { ServerActionHandlerRegistry } from './action-handler';
import {
Action, isResponseAction, ResponseAction, RequestModelAction, ComputedBoundsAction, LayoutAction, RequestBoundsAction,
RequestAction, generateRequestId, SetModelAction, UpdateModelAction, RejectAction, isRequestAction
Expand Down Expand Up @@ -54,25 +54,6 @@ export class DiagramServer {
this.actionHandlerRegistry = services.ServerActionHandlerRegistry;
}

/**
* @deprecated Use the `ServerActionHandlerRegistry` service instead
*/
onAction<A extends Action>(kind: string, handler: ServerActionHandler<A>) {
if (!this.actionHandlerRegistry) {
this.actionHandlerRegistry = new ServerActionHandlerRegistry();
}
this.actionHandlerRegistry.onAction(kind, handler);
}

/**
* @deprecated Use the `ServerActionHandlerRegistry` service instead
*/
removeActionHandler<A extends Action>(kind: string, handler: ServerActionHandler<A>) {
if (this.actionHandlerRegistry) {
this.actionHandlerRegistry.removeActionHandler(kind, handler);
}
}

/**
* Set the model and submit it to the client.
*/
Expand Down
84 changes: 2 additions & 82 deletions packages/sprotty/src/base/actions/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,99 +14,19 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { generateRequestId as generateRequestId2, Action as ProtocolAction} from 'sprotty-protocol/lib/actions';
import { JsonAny } from 'sprotty-protocol/lib/utils/json';
import { hasOwnProperty } from 'sprotty-protocol/lib/utils/object';
import { Action } from 'sprotty-protocol/lib/actions';

/**
* A list of actions with a label.
* Labeled actions are used to denote a group of actions in a user-interface context, e.g.,
* to define an entry in the command palette or in the context menu.
*/
export class LabeledAction {
constructor(readonly label: string, readonly actions: ProtocolAction[], readonly icon?: string) { }
constructor(readonly label: string, readonly actions: Action[], readonly icon?: string) { }
}

export function isLabeledAction(element: unknown): element is LabeledAction {
return element !== undefined
&& (<LabeledAction>element).label !== undefined
&& (<LabeledAction>element).actions !== undefined;
}

// Compatibility deprecation layer (will be removed with the graduation 1.0.0 release)

/**
* An action describes a change to the model declaratively.
* It is a plain data structure, and as such transferable between server and client. An action must never contain actual
* SModelElement instances, but either refer to them via their ids or contain serializable schema for model elements.
*
* @deprecated Use the declaration from `sprotty-protocol` instead.
*/
export interface Action {
readonly kind: string
}

/**
* @deprecated Use the declaration from `sprotty-protocol` instead.
*/
export function isAction(object?: unknown): object is Action {
return hasOwnProperty<string, string>(object, 'kind', 'string');
}

/**
* A request action is tied to the expectation of receiving a corresponding response action.
* The `requestId` property is used to match the received response with the original request.
*
* @deprecated Use the declaration from `sprotty-protocol` instead.
*/
export interface RequestAction<Res extends ResponseAction> extends Action {
readonly requestId: string
}

/**
* @deprecated Use the declaration from `sprotty-protocol` instead.
*/
export function isRequestAction(object?: unknown): object is RequestAction<ResponseAction> {
return isAction(object) && hasOwnProperty<string, string>(object, 'requestId', 'string');
}

/**
* Generate a unique `requestId` for a request action.
*
* @deprecated Use the declaration from `sprotty-protocol` instead.
*/
export const generateRequestId: () => string = generateRequestId2;

/**
* A response action is sent to respond to a request action. The `responseId` must match
* the `requestId` of the preceding request. In case the `responseId` is empty or undefined,
* the action is handled as standalone, i.e. it was fired without a preceding request.
*
* @deprecated Use the declaration from `sprotty-protocol` instead.
*/
export interface ResponseAction extends Action {
readonly responseId: string
}

/**
* @deprecated Use the declaration from `sprotty-protocol` instead.
*/
export function isResponseAction(object?: unknown): object is ResponseAction {
return isAction(object) && hasOwnProperty<string, string>(object, 'responseId', 'string')
&& object.responseId !== '';
}

/**
* A reject action is fired to indicate that a request must be rejected.
*
* @deprecated Use the declaration from `sprotty-protocol` instead.
*/
export class RejectAction implements ResponseAction {
static readonly KIND = 'rejectRequest';
readonly kind = RejectAction.KIND;

constructor(public readonly message: string,
public readonly responseId: string,
public readonly detail?: JsonAny) {}
}

46 changes: 3 additions & 43 deletions packages/sprotty/src/base/features/set-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,20 @@
********************************************************************************/

import { inject, injectable } from "inversify";
import {
Action, generateRequestId, RequestAction, ResponseAction,
RequestModelAction as ProtocolRequestModelAction, SetModelAction as ProtocolSetModelAction
} from "sprotty-protocol/lib/actions";
import { SModelRoot as SModelRootSchema } from 'sprotty-protocol/lib/model';
import { JsonPrimitive } from "sprotty-protocol/lib/utils/json";
import { Action, SetModelAction } from "sprotty-protocol/lib/actions";
import { CommandExecutionContext, ResetCommand } from "../commands/command";
import { SModelRootImpl } from "../model/smodel";
import { TYPES } from "../types";
import { InitializeCanvasBoundsCommand } from './initialize-canvas';

@injectable()
export class SetModelCommand extends ResetCommand {
static readonly KIND = ProtocolSetModelAction.KIND;
static readonly KIND = SetModelAction.KIND;

oldRoot: SModelRootImpl;
newRoot: SModelRootImpl;

constructor(@inject(TYPES.Action) protected readonly action: ProtocolSetModelAction) {
constructor(@inject(TYPES.Action) protected readonly action: SetModelAction) {
super();
}

Expand All @@ -55,38 +50,3 @@ export class SetModelCommand extends ResetCommand {
return action => action.kind === InitializeCanvasBoundsCommand.KIND;
}
}

// Compatibility deprecation layer (will be removed with the graduation 1.0.0 release)

/**
* Sent from the client to the model source (e.g. a DiagramServer) in order to request a model. Usually this
* is the first message that is sent to the source, so it is also used to initiate the communication.
* The response is a SetModelAction or an UpdateModelAction.
*
* @deprecated Use the declaration from `sprotty-protocol` instead.
*/
export class RequestModelAction implements ProtocolRequestModelAction {
static readonly KIND = 'requestModel';
readonly kind = RequestModelAction.KIND;

constructor(public readonly options?: { [key: string]: JsonPrimitive },
public readonly requestId = '') { }

/** Factory function to dispatch a request with the `IActionDispatcher` */
static create(options?: { [key: string]: JsonPrimitive }): RequestAction<SetModelAction> {
return new RequestModelAction(options, generateRequestId());
}
}

/**
* Sent from the model source to the client in order to set the model. If a model is already present, it is replaced.
*
* @deprecated Use the declaration from `sprotty-protocol` instead.
*/
export class SetModelAction implements ResponseAction, ProtocolSetModelAction {
static readonly KIND = 'setModel';
readonly kind = SetModelAction.KIND;

constructor(public readonly newRoot: SModelRootSchema,
public readonly responseId = '') { }
}
Loading

0 comments on commit 5cefac4

Please sign in to comment.