From bb9dc16cace353ccfb2e67a85e248ae91faaf962 Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Fri, 3 Sep 2021 09:25:16 +0200 Subject: [PATCH] chore(modeling): consistently create DI with attrs This fixes the existing DI creation methods in `BpmnFactory` and simplifies the related `ElementFactory` code that relied on it. In the past args got ignored and passing attrs to the created DI was not possible, now it is. BREAKING CHANGE: With this change the following `BpmnFactory` API methods got reworked to take (businessObject, attrs) as an input: * `BpmnFactory#createDiEdge` * `BpmnFactory#createDiShape` * `BpmnFactory#createDiPlane` --- lib/features/modeling/BpmnFactory.js | 16 ++++++------- lib/features/modeling/ElementFactory.js | 32 ++++++++++--------------- 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/lib/features/modeling/BpmnFactory.js b/lib/features/modeling/BpmnFactory.js index b334d4e8..b4f8f49d 100644 --- a/lib/features/modeling/BpmnFactory.js +++ b/lib/features/modeling/BpmnFactory.js @@ -83,11 +83,10 @@ BpmnFactory.prototype.createDiLabel = function() { }; -BpmnFactory.prototype.createDiShape = function(semantic, bounds, attrs) { - +BpmnFactory.prototype.createDiShape = function(semantic, attrs) { return this.create('bpmndi:BPMNShape', assign({ bpmnElement: semantic, - bounds: this.createDiBounds(bounds) + bounds: this.createDiBounds() }, attrs)); }; @@ -110,14 +109,15 @@ BpmnFactory.prototype.createDiWaypoint = function(point) { }; -BpmnFactory.prototype.createDiEdge = function(semantic, waypoints, attrs) { +BpmnFactory.prototype.createDiEdge = function(semantic, attrs) { return this.create('bpmndi:BPMNEdge', assign({ - bpmnElement: semantic + bpmnElement: semantic, + waypoints: this.createDiWaypoints([]) }, attrs)); }; -BpmnFactory.prototype.createDiPlane = function(semantic) { - return this.create('bpmndi:BPMNPlane', { +BpmnFactory.prototype.createDiPlane = function(semantic, attrs) { + return this.create('bpmndi:BPMNPlane', assign({ bpmnElement: semantic - }); + }, attrs)); }; \ No newline at end of file diff --git a/lib/features/modeling/ElementFactory.js b/lib/features/modeling/ElementFactory.js index 152312f3..ad6401c3 100644 --- a/lib/features/modeling/ElementFactory.js +++ b/lib/features/modeling/ElementFactory.js @@ -72,7 +72,7 @@ ElementFactory.prototype.createBpmnElement = function(elementType, attrs) { attrs = attrs || {}; var businessObject = attrs.businessObject, - di = attrs.di || {}; + di = attrs.di; if (!businessObject) { if (!attrs.type) { @@ -85,25 +85,18 @@ ElementFactory.prototype.createBpmnElement = function(elementType, attrs) { } if (!isModdleDi(di)) { + var diAttrs = assign( + di || {}, + { id: businessObject.id + '_di' } + ); + if (elementType === 'root') { - di = this._bpmnFactory.createDiPlane(businessObject, [], { - id: businessObject.id + '_di' - }); + di = this._bpmnFactory.createDiPlane(businessObject, diAttrs); } else if (elementType === 'connection') { - di = this._bpmnFactory.createDiEdge(businessObject, [], { - id: businessObject.id + '_di' - }); + di = this._bpmnFactory.createDiEdge(businessObject, diAttrs); } else { - di = this._bpmnFactory.createDiShape(businessObject, {}, { - id: businessObject.id + '_di' - }); - } - - if (attrs.di) { - assign(di, attrs.di); - - delete attrs.di; + di = this._bpmnFactory.createDiShape(businessObject, diAttrs); } } @@ -150,10 +143,11 @@ ElementFactory.prototype.createBpmnElement = function(elementType, attrs) { size = this.getDefaultSize(businessObject, di); attrs = assign({ - businessObject: businessObject, - di: di, id: businessObject.id - }, size, attrs); + }, size, attrs, { + businessObject: businessObject, + di: di + }); return this.baseCreate(elementType, attrs); };