chore(importer): attempt optimization

This commit is contained in:
Nico Rehwaldt 2014-09-08 19:04:18 +02:00
parent 179121880f
commit b5483b2565
1 changed files with 26 additions and 22 deletions

View File

@ -17,38 +17,42 @@ function importBpmnDiagram(diagram, definitions, done) {
var importer = diagram.get('bpmnImporter'),
eventBus = diagram.get('eventBus');
var warnings = [];
var error,
warnings = [];
var visitor = {
function parse(definitions) {
root: function(element) {
return importer.add(element);
},
var visitor = {
element: function(element, parentShape) {
return importer.add(element, parentShape);
},
root: function(element) {
return importer.add(element);
},
error: function(message, context) {
warnings.push({ message: message, context: context });
}
};
element: function(element, parentShape) {
return importer.add(element, parentShape);
},
var walker = new BpmnTreeWalker(visitor);
error: function(message, context) {
warnings.push({ message: message, context: context });
}
};
try {
eventBus.fire('import.start');
var walker = new BpmnTreeWalker(visitor);
// import
walker.handleDefinitions(definitions);
eventBus.fire('import.success', { warnings: warnings });
done(null, warnings);
} catch (e) {
eventBus.fire('import.error', { error: e });
done(e);
}
eventBus.fire('import.start');
try {
parse(definitions);
} catch (e) {
error = e;
}
eventBus.fire(error ? 'import.error' : 'import.success', { error: error, warnings: warnings });
done(error, warnings);
}
module.exports.importBpmnDiagram = importBpmnDiagram;