Updating Definition Model
During the development of your application, you may need to update the model. For example, a step that initially required setting a single property might now require setting two properties. If you simply extend the model by adding a new property, the Sequential Workflow Editor will crash for definitions created before the update.
myStep.property('username').value(createStringValueModel({}));
// If you just add a new property:
myStep.property('username').value(createStringValueModel({}));
myStep.property('nickname').value(createStringValueModel({}));
// the Sequential Workflow Editor will throw an error that the property 'nickname' is not defined for the old definitions.
To prevent this issue, you must update the old definitions. This can be done easily using the DefinitionWalker
class.
import { DefinitionWalker } from 'sequential-workflow-model';
const definition: Definition = { /* ... */ };
const walker = new DefinitionWalker();
walker.forEach(definition, step => {
if (step.type === 'myStep') {
if (step.properties.nickname === undefined) {
step.properties.nickname = step.properties.username;
}
}
});
You can apply this transformation either just before loading the definition or by updating the definitions in storage.
But what if you need to completely update the step? For instance, if the step now requires properties that cannot be mapped to the old properties or set with default values. In this case, we recommend creating a new step and hiding the old step in the toolbox. This approach ensures that old definitions continue to work with the old step, while new definitions use the new step.
createStepModel<PostMessageStep>('postMessage', 'task', step => {
step.toolbox(false);
step.property('username').value(createStringValueModel({}));
});
createStepModel<PostMessageV2Step>('postMessageV2', 'task', step => {
step.property('username').value(createStringValueModel({}));
step.property('nickname').value(createStringValueModel({}));
});