Making of bpmn-js Token Simulation

Understanding bpmn-js extensibility one token at a time.

Nico Rehwaldt

About Me

Agenda

1️⃣ Token simulation?

2️⃣ About bpmn-js

3️⃣ bpmn-js extensibility

4️⃣ How does token simulation plug in?

1️⃣ Token Simulation?

A picture is worth a thousand words.

A moving token is worth a whole bunch of static BPMN diagrams.

Token simulation overview

Core Idea: Token Flow = 💡

What it is not

2️⃣ About bpmn-js

bpmn-js

https://github.com/bpmn-io/bpmn-js

Modeling, Kids at Home

Nyan cat

3️⃣ bpmn-js Extensibility

A (BPMN) Diagram Toolbox

An Extensible Architecture

Extension Cases

📙 Select an Element

const bpmnModeler = new BpmnModeler();

const selection = bpmnModeler.get('selection');
const elementRegistry = bpmnModeler.get('elementRegistry');

selection.select([
  elementRegistry.get('Task_1')
]);

📙 Hook into Events

const bpmnModeler = new BpmnModeler();

const eventBus = bpmnModeler.get('eventBus');

eventBus.on('element.changed', function(event) {
  console.log('Changed', event.element);
});

📙 Model Programmatically

const modeling = bpmnModeler.get('modeling');

modeling.createShape(
  { type: 'bpmn:ServiceTask' },
  { x: 10, y: 20 }
);
002_wasdenn-2.gif

https://bpmn.io/blog/posts/2021-wasdenn-ai-modeling-assistant.html

📘 Implement a Service

// TaskSelection.js
export default function TaskSelection(selection, elementRegistry) {

  /**
   * Select this very special task
   */
  this.selectTask1 = function() {
    selection.select([
      elementRegistry.get('Task_1')
    ])
  };
}

📘 Create a Module

// TaskSelectionModule.js
import TaskSelection from './TaskSelection';

export default {
  taskSelection: [ 'type', TaskSelection ]
};

📘 Extend bpmn-js

import taskSelectionModule from './TaskSelectionModule';

const bpmnModeler = new BpmnModeler({
  additionalModules: [
    taskSelectionModule
  ]
});

const taskSelection = bpmnModeler.get('taskSelection');

taskSelection.selectTask1();

4️⃣ How does token simulation plug in?

Code Review!

In a Nutshell

Thank you. Questions?

Contribute to Token Simulation

You like the token simulation tool? Consider contributing on Github and help us to make it even better ❤️.

Resources