Skip to content

Commit

Permalink
Fix broken reimport (#166)
Browse files Browse the repository at this point in the history
* Fixes broken reimport from issue #165

* Clear the cache when loading a new diagram

* Clean diff

* Add comments

Co-authored-by: jan.ladleif <jan.ladleif@hpi.uni-potsdam.de>
Co-authored-by: Jan Ladleif <jan.ladleif@hpi.de>
  • Loading branch information
3 people committed Oct 29, 2020
1 parent 9446d38 commit a8c990a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/Modeler.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import BpmnDiOrdering from './features/di-ordering';
import ChoreoSpaceToolModule from './features/space-tool';

import {
displayChoreography
displayChoreography,
clearShapeCache
} from './import/ImportHandler';


Expand All @@ -39,6 +40,11 @@ Modeler.prototype.open = function(bpmnDiagramOrId) {
return displayChoreography(this, bpmnDiagramOrId);
};

Modeler.prototype.importXML = function(xml, bpmnDiagram) {
clearShapeCache();
return BaseModeler.prototype.importXML.call(this, xml, bpmnDiagram);
};

Modeler.prototype.clear = function() {
// Skip clearing of the DI references introduced in this commit by bpmn-js:
// https://github.com/bpmn-io/bpmn-js/commit/0c71ad30a0c945679851e73b15647f634f2b9bb8
Expand Down
8 changes: 7 additions & 1 deletion lib/Viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import inherits from 'inherits';
import CoreModule from './core';

import {
displayChoreography
displayChoreography,
clearShapeCache
} from './import/ImportHandler';


Expand Down Expand Up @@ -35,6 +36,11 @@ Viewer.prototype.open = function(bpmnDiagramOrId) {
return displayChoreography(this, bpmnDiagramOrId);
};

Viewer.prototype.importXML = function(xml, bpmnDiagram) {
clearShapeCache();
return BaseViewer.prototype.importXML.call(this, xml, bpmnDiagram);
};

Viewer.prototype.clear = function() {
// Skip clearing of the DI references introduced in this commit by bpmn-js:
// https://github.com/bpmn-io/bpmn-js/commit/0c71ad30a0c945679851e73b15647f634f2b9bb8
Expand Down
8 changes: 8 additions & 0 deletions lib/import/ImportHandler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
let shapeCache = {};

/**
* Clear the cached shapes. This function should be called when loading a new diagram,
* since the old cache might lead to errors if elements with the same IDs are encountered.
*/
export function clearShapeCache() {
shapeCache = {};
}

/**
* Display a specific choreography contained in the definitions attached to a viewer.
*
Expand Down

0 comments on commit a8c990a

Please sign in to comment.