chore(Viewer): remove failSafeUtil

This commit is contained in:
Nico Rehwaldt 2014-08-01 07:47:36 +02:00
parent 826d798f19
commit e337ffe246
2 changed files with 18 additions and 37 deletions

View File

@ -1,24 +0,0 @@
var _ = require('lodash');
function failSafeAsync(fn) {
return function() {
var args = Array.prototype.slice.call(arguments);
var done = args[args.length - 1];
if (!done || !_.isFunction(done)) {
done = function(e) {
throw e;
};
}
try {
fn.apply(this, args);
} catch (e) {
done(e);
}
};
}
module.exports.failSafeAsync = failSafeAsync;

View File

@ -5,8 +5,7 @@ var Diagram = require('diagram-js'),
$ = require('jquery'),
_ = require('lodash');
var Importer = require('./import/Importer'),
util = require('./Util');
var Importer = require('./import/Importer');
function getSvgContents(diagram) {
@ -176,21 +175,27 @@ Viewer.prototype.invoke = function(fn) {
return this.diagram.invoke(fn);
};
Viewer.prototype.importDefinitions = util.failSafeAsync(function(definitions, done) {
Viewer.prototype.importDefinitions = function(definitions, done) {
var diagram = this.diagram;
if (diagram) {
this.clear();
// use try/catch to not swallow synchronous exceptions
// that may be raised during model parsing
try {
if (diagram) {
this.clear();
}
this.diagram = diagram = this._createDiagram(this.options.modules);
this.definitions = definitions;
this._init(diagram);
Importer.importBpmnDiagram(diagram, definitions, done);
} catch (e) {
done(e);
}
this.diagram = diagram = this._createDiagram(this.options.modules);
this.definitions = definitions;
this._init(diagram);
Importer.importBpmnDiagram(diagram, definitions, done);
});
};
Viewer.prototype._init = function(diagram) {
initListeners(diagram, this.__listeners || []);