Revert "feat(util/model): avoid persisting empty property element containers"
This reverts commit 86c0a0aa75
.
This commit is contained in:
parent
fdc756b442
commit
b5c65f0b42
|
@ -39,10 +39,6 @@ module.exports = ModelCloneHelper;
|
|||
ModelCloneHelper.prototype.clone = function(oldElement, newElement, properties) {
|
||||
this._newElement = newElement;
|
||||
|
||||
// this property allows us to avoid ending up with empty (xml) tags
|
||||
// f.ex: if extensionElements.values is empty, don't set it
|
||||
this._hasNestedProperty = false;
|
||||
|
||||
// we want the extensionElements to be cloned last
|
||||
// so that they can check certain properties
|
||||
properties = sort(properties, function(prop) {
|
||||
|
@ -53,7 +49,7 @@ ModelCloneHelper.prototype.clone = function(oldElement, newElement, properties)
|
|||
var oldElementProp = oldElement.get(propName),
|
||||
newElementProp = newElement.get(propName),
|
||||
propDescriptor = newElement.$model.getPropertyDescriptor(newElement, propName),
|
||||
newProperty, name;
|
||||
name;
|
||||
|
||||
// we're not interested in cloning:
|
||||
// - same values from simple types
|
||||
|
@ -76,25 +72,14 @@ ModelCloneHelper.prototype.clone = function(oldElement, newElement, properties)
|
|||
forEach(oldElementProp, function(extElement) {
|
||||
var newProp = this._deepClone(extElement);
|
||||
|
||||
if (this._hasNestedProperty) {
|
||||
newProp.$parent = newElement;
|
||||
newProp.$parent = newElement;
|
||||
|
||||
newElementProp.push(newProp);
|
||||
}
|
||||
|
||||
this._hasNestedProperty = false;
|
||||
newElementProp.push(newProp);
|
||||
}, this);
|
||||
|
||||
} else {
|
||||
name = propName.replace(/bpmn:/, '');
|
||||
|
||||
newProperty = this._deepClone(oldElementProp);
|
||||
|
||||
if (this._hasNestedProperty) {
|
||||
newElement[name] = newProperty;
|
||||
}
|
||||
|
||||
this._hasNestedProperty = false;
|
||||
newElement[name] = this._deepClone(oldElementProp);
|
||||
}
|
||||
}, this);
|
||||
|
||||
|
@ -125,15 +110,12 @@ ModelCloneHelper.prototype._deepClone = function _deepClone(element) {
|
|||
return prop !== '$type';
|
||||
});
|
||||
|
||||
if (!properties.length) {
|
||||
this._hasNestedProperty = true;
|
||||
}
|
||||
|
||||
forEach(properties, function(propName) {
|
||||
// check if the element has this property defined
|
||||
if (element[propName] !== undefined && (element[propName].$type || isArray(element[propName]))) {
|
||||
|
||||
if (isArray(element[propName])) {
|
||||
newProp[propName] = [];
|
||||
|
||||
forEach(element[propName], function(property) {
|
||||
var extProp = element.$model.getTypeDescriptor(property.$type),
|
||||
|
@ -163,27 +145,15 @@ ModelCloneHelper.prototype._deepClone = function _deepClone(element) {
|
|||
|
||||
newDeepProp.$parent = newProp;
|
||||
|
||||
if (!newProp[propName]) {
|
||||
newProp[propName] = [];
|
||||
}
|
||||
|
||||
this._hasNestedProperty = true;
|
||||
|
||||
newProp[propName].push(newDeepProp);
|
||||
}, this);
|
||||
|
||||
} else if (element[propName].$type) {
|
||||
newProp[propName] = this._deepClone(element[propName]);
|
||||
|
||||
if (newProp[propName]) {
|
||||
this._hasNestedProperty = true;
|
||||
|
||||
newProp[propName].$parent = newProp;
|
||||
}
|
||||
newProp[propName].$parent = newProp;
|
||||
}
|
||||
} else {
|
||||
this._hasNestedProperty = true;
|
||||
|
||||
// just assign directly if it's a value
|
||||
newProp[propName] = element[propName];
|
||||
}
|
||||
|
|
|
@ -214,7 +214,7 @@ describe('util/ModelCloneHelper', function() {
|
|||
var extElem = userTask.extensionElements;
|
||||
|
||||
// then
|
||||
expect(extElem).to.not.exist;
|
||||
expect(extElem.values).to.be.empty;
|
||||
}));
|
||||
|
||||
});
|
||||
|
@ -236,12 +236,10 @@ describe('util/ModelCloneHelper', function() {
|
|||
});
|
||||
|
||||
var signalEvtDef = moddle.create('bpmn:SignalEventDefinition', {
|
||||
async: true
|
||||
timeDuration: 'foobar'
|
||||
});
|
||||
|
||||
var multiInst = moddle.create('bpmn:MultiInstanceLoopCharacteristics', {
|
||||
elementVariable: 'foobar'
|
||||
});
|
||||
var multiInst = moddle.create('bpmn:MultiInstanceLoopCharacteristics');
|
||||
|
||||
var timerStartEvent = moddle.create('bpmn:StartEvent', {
|
||||
extensionElements: createExtElems(),
|
||||
|
@ -372,7 +370,7 @@ describe('util/ModelCloneHelper', function() {
|
|||
var extElems = clonedElement.extensionElements;
|
||||
|
||||
// then
|
||||
expect(extElems).not.exist;
|
||||
expect(extElems.values).be.empty;
|
||||
}));
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue