fix(Viewer): do not cache moddle
This may have unwanted side-effects, i.e. when using id validation and caching. We must ensure the meta-model element is actually instance stateless in order to safely cache it.
This commit is contained in:
parent
4854c96067
commit
788b143f27
|
@ -129,7 +129,7 @@ Viewer.prototype.importXML = function(xml, done) {
|
|||
|
||||
var self = this;
|
||||
|
||||
this.moddle = this.moddle || this.createModdle();
|
||||
this.moddle = this.createModdle();
|
||||
|
||||
this.moddle.fromXML(xml, 'bpmn:Definitions', function(err, definitions, context) {
|
||||
|
||||
|
@ -167,8 +167,7 @@ Viewer.prototype.saveXML = function(options, done) {
|
|||
};
|
||||
|
||||
Viewer.prototype.createModdle = function() {
|
||||
var options = this.options;
|
||||
return options.moddle || new BpmnModdle(options.moddleExtensions);
|
||||
return new BpmnModdle(this.options.moddleExtensions);
|
||||
};
|
||||
|
||||
Viewer.prototype.saveSVG = function(options, done) {
|
||||
|
|
|
@ -19,8 +19,8 @@ describe('Modeler', function() {
|
|||
function createModeler(xml, done) {
|
||||
var modeler = new Modeler({ container: container });
|
||||
|
||||
modeler.importXML(xml, function(err) {
|
||||
done(err, modeler);
|
||||
modeler.importXML(xml, function(err, warnings) {
|
||||
done(err, warnings, modeler);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -37,13 +37,42 @@ describe('Modeler', function() {
|
|||
});
|
||||
|
||||
|
||||
iit('should re-import simple process', function(done) {
|
||||
|
||||
var xml = fs.readFileSync('test/fixtures/bpmn/simple.bpmn', 'utf8');
|
||||
|
||||
// given
|
||||
createModeler(xml, function(err, warnings, modeler) {
|
||||
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
// when
|
||||
// mimic re-import of same diagram
|
||||
modeler.importXML(xml, function(err, warnings) {
|
||||
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
// then
|
||||
expect(warnings.length).toBe(0);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('overlay support', function() {
|
||||
|
||||
it('should allow to add overlays', function(done) {
|
||||
|
||||
var xml = fs.readFileSync('test/fixtures/bpmn/simple.bpmn', 'utf8');
|
||||
|
||||
createModeler(xml, function(err, viewer) {
|
||||
createModeler(xml, function(err, warnings, viewer) {
|
||||
|
||||
// given
|
||||
var overlays = viewer.get('overlays'),
|
||||
|
@ -91,7 +120,7 @@ describe('Modeler', function() {
|
|||
|
||||
var xml = fs.readFileSync('test/fixtures/bpmn/simple.bpmn', 'utf8');
|
||||
|
||||
createModeler(xml, function(err, viewer) {
|
||||
createModeler(xml, function(err, warnings, viewer) {
|
||||
|
||||
// given
|
||||
var bendpointMove = viewer.get('bendpointMove'),
|
||||
|
@ -141,7 +170,7 @@ describe('Modeler', function() {
|
|||
|
||||
var xml = fs.readFileSync('test/fixtures/bpmn/simple.bpmn', 'utf8');
|
||||
|
||||
createModeler(xml, function(err, modeler) {
|
||||
createModeler(xml, function(err, warnings, modeler) {
|
||||
|
||||
expect(modeler.get('bpmnjs')).toBe(modeler);
|
||||
|
||||
|
|
|
@ -42,6 +42,32 @@ describe('Viewer', function() {
|
|||
});
|
||||
|
||||
|
||||
it('should re-import simple process', function(done) {
|
||||
|
||||
var xml = fs.readFileSync('test/fixtures/bpmn/simple.bpmn', 'utf8');
|
||||
|
||||
// given
|
||||
createViewer(xml, function(err, warnings, viewer) {
|
||||
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
// when
|
||||
// mimic re-import of same diagram
|
||||
viewer.importXML(xml, function(err, warnings) {
|
||||
|
||||
// then
|
||||
expect(err).toBeFalsy();
|
||||
expect(warnings.length).toBe(0);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('import events', function() {
|
||||
|
||||
it('should fire <import.*> events', function(done) {
|
||||
|
|
Loading…
Reference in New Issue