From c853e88e54672a4da6e42a9b339135d7e228b2e5 Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Tue, 21 Mar 2017 07:23:57 +0100 Subject: [PATCH] chore(modeling): do not expose ElementFactory helpers Less API surface => BETTER. --- lib/features/modeling/ElementFactory.js | 55 ++++++++++++++++--------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/lib/features/modeling/ElementFactory.js b/lib/features/modeling/ElementFactory.js index 261cdd2c..2155a7c1 100644 --- a/lib/features/modeling/ElementFactory.js +++ b/lib/features/modeling/ElementFactory.js @@ -81,7 +81,7 @@ ElementFactory.prototype.createBpmnElement = function(elementType, attrs) { delete attrs.colors; } - this.setAttrs(businessObject, attrs, [ + applyAttributes(businessObject, attrs, [ 'processRef', 'isInterrupting', 'associationDirection', @@ -89,7 +89,7 @@ ElementFactory.prototype.createBpmnElement = function(elementType, attrs) { ]); if (attrs.isExpanded) { - this.setAttr(businessObject.di, attrs, 'isExpanded'); + applyAttribute(businessObject.di, attrs, 'isExpanded'); } if (is(businessObject, 'bpmn:ExclusiveGateway')) { @@ -122,23 +122,6 @@ ElementFactory.prototype.createBpmnElement = function(elementType, attrs) { }; -ElementFactory.prototype.setAttrs = function(element, attrs, properties) { - - forEach(properties, function(property) { - if (attrs[property] !== undefined) { - this.setAttr(element, attrs, property); - } - }, this); -}; - - -ElementFactory.prototype.setAttr = function(element, attrs, property) { - element[property] = attrs[property]; - - delete attrs[property]; -}; - - ElementFactory.prototype._getDefaultSize = function(semantic) { if (is(semantic, 'bpmn:SubProcess')) { @@ -200,3 +183,37 @@ ElementFactory.prototype.createParticipantShape = function(collapsed) { return this.createShape(attrs); }; + + +//////////// helpers //////////////////////////////////// + +/** + * Apply attributes from a map to the given element, + * remove attribute from the map on application. + * + * @param {Base} element + * @param {Object} attrs (in/out map of attributes) + * @param {Array} attributeNames name of attributes to apply + */ +function applyAttributes(element, attrs, attributeNames) { + + forEach(attributeNames, function(property) { + if (attrs[property] !== undefined) { + applyAttribute(element, attrs, property); + } + }); +} + +/** + * Apply named property to element and drain it from the attrs + * collection. + * + * @param {Base} element + * @param {Object} attrs (in/out map of attributes) + * @param {String} attributeName to apply + */ +function applyAttribute(element, attrs, attributeName) { + element[attributeName] = attrs[attributeName]; + + delete attrs[attributeName]; +} \ No newline at end of file