mirror of
https://github.com/bpmn-io/bpmn-js.git
synced 2025-08-06 09:39:14 +08:00
feat: allow to type services and events
This PR builds on upon diagram-js provided service and event typing: * https://github.com/bpmn-io/diagram-js/pull/862 It allows you to specify (public) types exposed by your BPMN toolkit trough a ServiceMap. Events exposed are parsed from the EventBus dynamic types. Closes #2121
This commit is contained in:

committed by
Nico Rehwaldt

parent
4d0c0f4f65
commit
edfec4cdc8
@ -1,6 +1,6 @@
|
||||
import CommandStack from 'diagram-js/lib/command/CommandStack';
|
||||
|
||||
import { Event } from 'diagram-js/lib/core/EventBus';
|
||||
import EventBus, { Event } from 'diagram-js/lib/core/EventBus';
|
||||
|
||||
import BaseViewer, {
|
||||
ImportDoneEvent,
|
||||
@ -11,6 +11,7 @@ import BaseViewer, {
|
||||
} from './BaseViewer';
|
||||
|
||||
import OverlaysModule from 'diagram-js/lib/features/overlays';
|
||||
import Canvas from 'diagram-js/lib/core/Canvas';
|
||||
|
||||
const viewer = new BaseViewer();
|
||||
|
||||
@ -170,4 +171,37 @@ export function testViewer(viewer: BaseViewer) {
|
||||
});
|
||||
|
||||
viewer.on<Event>('detach', () => {});
|
||||
}
|
||||
}
|
||||
|
||||
// typed API usage
|
||||
|
||||
type FooEvent = {
|
||||
/**
|
||||
* Very cool field!
|
||||
*/
|
||||
foo: string;
|
||||
};
|
||||
|
||||
type EventMap = {
|
||||
|
||||
foo: FooEvent
|
||||
};
|
||||
|
||||
type TypeMap = {
|
||||
canvas: Canvas,
|
||||
eventBus: EventBus<EventMap>
|
||||
};
|
||||
|
||||
const typedViewer = new BaseViewer<TypeMap>();
|
||||
|
||||
const bus = typedViewer.get('eventBus');
|
||||
|
||||
const canvas = typedViewer.get('canvas');
|
||||
|
||||
canvas.zoom('fit-viewport');
|
||||
|
||||
typedViewer.on('foo', event => {
|
||||
console.log(event.foo);
|
||||
});
|
||||
|
||||
typedViewer.get('eventBus').on('foo', e => console.log(e.foo));
|
||||
|
Reference in New Issue
Block a user