Skip to main content

Definition Activator

When you have created a definition model you may want to use it to create a definition. The most popular use case is to create a start definition for the designer.

In the below model we created a simple definition model with a single step called pingIp. Also we want to place this step in the root sequence.

interface PingIpStep extends Step {
type: 'pingIp';
componentType: 'task';
properties: {
ip: string;
}
}

const definitionModel = createDefinitionModel(model => {
model.root((root) => {
root.sequence().value(createSequenceValueModel({
sequence: ['pingIp']
}));
});

model.steps([
createStepModel<PingIpStep>('pingIp', 'task', step => {
step.property('ip').value(
createStringValueModel({
defaultValue: '127.0.0.1'
})
);
})
]);
});

const editorProvider = EditorProvider.create(definitionModel, {
uidGenerator: Uid.next
});

To activate the whole definition you need to call the activateDefinition method of the EditorProvider class.

const definition: Definition = editorProvider.activateDefinition();
/* =>
{
"properties": {},
"sequence": [
{
"id": "1fc989343ad4f48f48ee9b9b03c32fb5",
"type": "pingIp",
"componentType": "task",
"properties": {
"ip": "127.0.0.1"
},
"name": "PingIp"
}
]
}
*/

You can also activate only a single step by calling the activateStep method.

const step = editorProvider.activateStep('pingIp') as PingIpStep;
/* =>
{
"id": "1fc989343ad4f48f48ee9b9b03c32fb5",
"type": "pingIp",
"componentType": "task",
"properties": {
"ip": "127.0.0.1"
},
"name": "PingIp"
}
*/

The EditorProvider class should be used only in the browser. If you want to activate a definition on the server you should use the ModelActivator class.

import { ModelActivator } from 'sequential-workflow-editor-model';

const uidGenerator = () => /* return unique id */;
const activator = ModelActivator.create(definitionModel, uidGenerator);

const definition = activator.activateDefinition();
const step = activator.activateStep('pingIp');