Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sprotty-protocol

Package Overview
Dependencies
Maintainers
4
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sprotty-protocol - npm Package Compare versions

Comparing version 0.11.0-next.18 to 0.11.0-next.09a994a.27

lib/action-handler.d.ts

8

lib/diagram-server.d.ts

@@ -16,2 +16,3 @@ /********************************************************************************

********************************************************************************/
import { ServerActionHandler, ServerActionHandlerRegistry } from './action-handler';
import { Action, ResponseAction, RequestModelAction, ComputedBoundsAction, LayoutAction, RequestAction } from './actions';

@@ -32,11 +33,11 @@ import { DiagramServices, DiagramState, IDiagramGenerator, IModelLayoutEngine } from './diagram-services';

protected readonly layoutEngine?: IModelLayoutEngine;
protected actionHandlerRegistry?: ServerActionHandlerRegistry;
protected readonly requests: Map<string, Deferred<ResponseAction>>;
protected readonly handlers: Map<string, ServerActionHandler<Action>[]>;
constructor(dispatch: <A extends Action>(action: A) => Promise<void>, services: DiagramServices);
/**
* Add an action handler to be called when an action of the specified kind is received.
* @deprecated Use the `ServerActionHandlerRegistry` service instead
*/
onAction<A extends Action>(kind: string, handler: ServerActionHandler<A>): void;
/**
* Remove an action handler that was previously added with `onAction`.
* @deprecated Use the `ServerActionHandlerRegistry` service instead
*/

@@ -93,3 +94,2 @@ removeActionHandler<A extends Action>(kind: string, handler: ServerActionHandler<A>): void;

}
export declare type ServerActionHandler<A extends Action = Action> = (action: A, state: DiagramState, server: DiagramServer) => Promise<void>;
//# sourceMappingURL=diagram-server.d.ts.map

@@ -54,2 +54,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var action_handler_1 = require("./action-handler");
var actions_1 = require("./actions");

@@ -72,28 +73,22 @@ var async_1 = require("./utils/async");

this.requests = new Map();
this.handlers = new Map();
this.dispatch = dispatch;
this.diagramGenerator = services.DiagramGenerator;
this.layoutEngine = services.ModelLayoutEngine;
this.actionHandlerRegistry = services.ServerActionHandlerRegistry;
}
/**
* Add an action handler to be called when an action of the specified kind is received.
* @deprecated Use the `ServerActionHandlerRegistry` service instead
*/
DiagramServer.prototype.onAction = function (kind, handler) {
if (this.handlers.has(kind)) {
this.handlers.get(kind).push(handler);
if (!this.actionHandlerRegistry) {
this.actionHandlerRegistry = new action_handler_1.ServerActionHandlerRegistry();
}
else {
this.handlers.set(kind, [handler]);
}
this.actionHandlerRegistry.onAction(kind, handler);
};
/**
* Remove an action handler that was previously added with `onAction`.
* @deprecated Use the `ServerActionHandlerRegistry` service instead
*/
DiagramServer.prototype.removeActionHandler = function (kind, handler) {
var list = this.handlers.get(kind);
if (list) {
var index = list.indexOf(handler);
if (index >= 0) {
list.splice(index, 1);
}
if (this.actionHandlerRegistry) {
this.actionHandlerRegistry.removeActionHandler(kind, handler);
}

@@ -209,4 +204,5 @@ };

var _this = this;
// Find a matching action handler in the registered map
var handlers = this.handlers.get(action.kind);
var _a;
// Find a matching action handler in the registry
var handlers = (_a = this.actionHandlerRegistry) === null || _a === void 0 ? void 0 : _a.getHandler(action.kind);
if (handlers && handlers.length === 1) {

@@ -213,0 +209,0 @@ return handlers[0](action, this.state, this);

@@ -16,2 +16,3 @@ /********************************************************************************

********************************************************************************/
import { ServerActionHandlerRegistry } from './action-handler';
import { SModelRoot } from './model';

@@ -35,2 +36,3 @@ import { JsonMap } from './utils/json';

readonly ModelLayoutEngine?: IModelLayoutEngine;
readonly ServerActionHandlerRegistry?: ServerActionHandlerRegistry;
}

@@ -37,0 +39,0 @@ /**

{
"name": "sprotty-protocol",
"version": "0.11.0-next.18+554a2dd",
"version": "0.11.0-next.09a994a.27+09a994a",
"description": "TypeScript declarations for Sprotty to be used both in browser and Node.js context",

@@ -62,3 +62,3 @@ "license": "(EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0)",

],
"gitHead": "554a2ddb182ff7634127077830bf02c51f8d1d29"
"gitHead": "09a994a32e040d6f1c22113a0dc1af0a580d008b"
}

@@ -20,4 +20,5 @@ /********************************************************************************

import { Action, ComputedBoundsAction, RequestBoundsAction, RequestModelAction, SetModelAction } from './actions';
import { DiagramServer, ServerActionHandler } from './diagram-server';
import { DiagramServer } from './diagram-server';
import { BoundsAware, SModelRoot } from './model';
import { ServerActionHandler, ServerActionHandlerRegistry } from './action-handler';

@@ -43,4 +44,9 @@ declare function setImmediate(callback: () => void): void;

describe('DiagramServer', () => {
function createServer(): { server: DiagramServer, dispatched: Action[] } {
function createServer(): {
server: DiagramServer,
actionHandlerRegistry: ServerActionHandlerRegistry,
dispatched: Action[]
} {
const dispatched: Action[] = [];
const actionHandlerRegistry = new ServerActionHandlerRegistry();
const server = new DiagramServer(

@@ -63,5 +69,6 @@ async a => {

}
}
},
ServerActionHandlerRegistry: actionHandlerRegistry
});
return { server, dispatched };
return { server, actionHandlerRegistry, dispatched };
}

@@ -175,4 +182,4 @@

it('calls a registered action handler', async () => {
const { server, dispatched } = createServer();
server.onAction('foo', (_, state, server) => {
const { server, actionHandlerRegistry, dispatched } = createServer();
actionHandlerRegistry.onAction('foo', (_, state, server) => {
state.revision = -7;

@@ -189,3 +196,3 @@ server.dispatch({ kind: 'bar' });

it('does not call an unregistered action handler', async () => {
const { server, dispatched } = createServer();
const { server, actionHandlerRegistry, dispatched } = createServer();
const handler: ServerActionHandler = (_, state, server) => {

@@ -196,4 +203,4 @@ state.revision = -7;

};
server.onAction('foo', handler);
server.removeActionHandler('foo', handler);
actionHandlerRegistry.onAction('foo', handler);
actionHandlerRegistry.removeActionHandler('foo', handler);
await server.accept({ kind: 'foo' });

@@ -200,0 +207,0 @@ expect((server as any).state.revision).to.equal(0);

@@ -17,2 +17,3 @@ /********************************************************************************

import { ServerActionHandler, ServerActionHandlerRegistry } from './action-handler';
import {

@@ -46,4 +47,4 @@ Action, isResponseAction, ResponseAction, RequestModelAction, ComputedBoundsAction, LayoutAction, RequestBoundsAction,

protected readonly layoutEngine?: IModelLayoutEngine;
protected actionHandlerRegistry?: ServerActionHandlerRegistry;
protected readonly requests = new Map<string, Deferred<ResponseAction>>();
protected readonly handlers = new Map<string, ServerActionHandler[]>();

@@ -55,25 +56,21 @@ constructor(dispatch: <A extends Action>(action: A) => Promise<void>,

this.layoutEngine = services.ModelLayoutEngine;
this.actionHandlerRegistry = services.ServerActionHandlerRegistry;
}
/**
* Add an action handler to be called when an action of the specified kind is received.
* @deprecated Use the `ServerActionHandlerRegistry` service instead
*/
onAction<A extends Action>(kind: string, handler: ServerActionHandler<A>) {
if (this.handlers.has(kind)) {
this.handlers.get(kind)!.push(handler);
} else {
this.handlers.set(kind, [handler]);
if (!this.actionHandlerRegistry) {
this.actionHandlerRegistry = new ServerActionHandlerRegistry();
}
this.actionHandlerRegistry.onAction(kind, handler);
}
/**
* Remove an action handler that was previously added with `onAction`.
* @deprecated Use the `ServerActionHandlerRegistry` service instead
*/
removeActionHandler<A extends Action>(kind: string, handler: ServerActionHandler<A>) {
const list = this.handlers.get(kind);
if (list) {
const index = list.indexOf(handler);
if (index >= 0) {
list.splice(index, 1);
}
if (this.actionHandlerRegistry) {
this.actionHandlerRegistry.removeActionHandler(kind, handler);
}

@@ -186,4 +183,4 @@ }

protected handleAction(action: Action): Promise<void> {
// Find a matching action handler in the registered map
const handlers = this.handlers.get(action.kind);
// Find a matching action handler in the registry
const handlers = this.actionHandlerRegistry?.getHandler(action.kind);
if (handlers && handlers.length === 1) {

@@ -290,3 +287,1 @@ return handlers[0](action, this.state, this);

}
export type ServerActionHandler<A extends Action = Action> = (action: A, state: DiagramState, server: DiagramServer) => Promise<void>;

@@ -17,2 +17,3 @@ /********************************************************************************

import { ServerActionHandlerRegistry } from './action-handler';
import { SModelRoot } from './model';

@@ -39,2 +40,3 @@ import { JsonMap } from './utils/json';

readonly ModelLayoutEngine?: IModelLayoutEngine
readonly ServerActionHandlerRegistry?: ServerActionHandlerRegistry
}

@@ -41,0 +43,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc