From daee95743da021316885c69e8ac4b4a667f6ff1a Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Fri, 12 Apr 2019 11:56:00 +0200 Subject: [PATCH] chore(Viewer): type BPMNDiagram arg where possible --- lib/Viewer.js | 42 +++++++++++++++++++++--------------------- lib/import/Importer.js | 24 ++++++++++++------------ 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/lib/Viewer.js b/lib/Viewer.js index 61226b35..cd630a78 100644 --- a/lib/Viewer.js +++ b/lib/Viewer.js @@ -70,15 +70,14 @@ function ensureUnit(val) { /** - * * Find BPMNDiagram in definitions by ID * - * @param {ModdleElement} definitions + * @param {ModdleElement} definitions * @param {String} diagramId * - * @return {Diagram|null} + * @return {ModdleElement|null} */ -function findDiagram(definitions, diagramId) { +function findBPMNDiagram(definitions, diagramId) { if (!diagramId) { return null; } @@ -174,14 +173,14 @@ inherits(Viewer, Diagram); * You can use these events to hook into the life-cycle. * * @param {String} xml the BPMN 2.0 xml - * @param {String} [diagramId] id of the diagram to render (if not provided, the first one will be rendered) + * @param {ModdleElement|String} [bpmnDiagram] BPMN diagram or id of diagram to render (if not provided, the first one will be rendered) * @param {Function} [done] invoked with (err, warnings=[]) */ -Viewer.prototype.importXML = function(xml, diagramId, done) { +Viewer.prototype.importXML = function(xml, bpmnDiagram, done) { - if (isFunction(diagramId)) { - done = diagramId; - diagramId = null; + if (isFunction(bpmnDiagram)) { + done = bpmnDiagram; + bpmnDiagram = null; } // done is optional @@ -215,7 +214,7 @@ Viewer.prototype.importXML = function(xml, diagramId, done) { self._setDefinitions(definitions); - self.open(diagramId, function(err, importWarnings) { + self.open(bpmnDiagram, function(err, importWarnings) { var allWarnings = [].concat(parseWarnings, importWarnings || []); self._emit('import.done', { error: err, warnings: allWarnings }); @@ -240,17 +239,18 @@ Viewer.prototype.importXML = function(xml, diagramId, done) { * * You can use these events to hook into the life-cycle. * - * @param {String|Diagram} [diagram] id or the diagram to open + * @param {String|ModdleElement} [bpmnDiagramOrId] id or the diagram to open * @param {Function} [done] invoked with (err, warnings=[]) */ -Viewer.prototype.open = function(diagram, done) { +Viewer.prototype.open = function(bpmnDiagramOrId, done) { - if (isFunction(diagram)) { - done = diagram; - diagram = null; + if (isFunction(bpmnDiagramOrId)) { + done = bpmnDiagramOrId; + bpmnDiagramOrId = null; } var definitions = this._definitions; + var bpmnDiagram = bpmnDiagramOrId; // done is optional done = done || function() {}; @@ -259,24 +259,24 @@ Viewer.prototype.open = function(diagram, done) { return done(new Error('no XML imported')); } - if (typeof diagram === 'string') { - diagram = findDiagram(definitions, diagram); + if (typeof bpmnDiagramOrId === 'string') { + bpmnDiagram = findBPMNDiagram(definitions, bpmnDiagramOrId); - if (!diagram) { - return done(new Error('no diagram to display')); + if (!bpmnDiagram) { + return done(new Error('BPMNDiagram <' + bpmnDiagramOrId + '> not found')); } } + // clear existing rendered diagram // catch synchronous exceptions during #clear() try { - // clear existing rendered diagram this.clear(); } catch (error) { return done(error); } // perform graphical import - return importBpmnDiagram(this, definitions, diagram, done); + return importBpmnDiagram(this, definitions, bpmnDiagram, done); }; /** diff --git a/lib/import/Importer.js b/lib/import/Importer.js index e431720d..3a58d8c5 100644 --- a/lib/import/Importer.js +++ b/lib/import/Importer.js @@ -9,17 +9,17 @@ import { * * Errors and warnings are reported through the specified callback. * - * @param {Diagram} diagram - * @param {ModdleElement} definitions - * @param {ModdleElement} [selectedDiagram] the BPMNDiagram element selected to be rendered + * @param {djs.Diagram} diagram + * @param {ModdleElement} definitions + * @param {ModdleElement} [bpmnDiagram] the diagram to be rendered * (if not provided, the first one will be rendered) * @param {Function} done the callback, invoked with (err, [ warning ]) once the import is done */ -export function importBpmnDiagram(diagram, definitions, selectedDiagram, done) { +export function importBpmnDiagram(diagram, definitions, bpmnDiagram, done) { - if (isFunction(selectedDiagram)) { - done = selectedDiagram; - selectedDiagram = null; + if (isFunction(bpmnDiagram)) { + done = bpmnDiagram; + bpmnDiagram = null; } var importer, @@ -33,10 +33,10 @@ export function importBpmnDiagram(diagram, definitions, selectedDiagram, done) { * Walk the diagram semantically, importing (=drawing) * all elements you encounter. * - * @param {ModdleElement} definitions - * @param {ModdleElement} selectedDiagram + * @param {ModdleElement} definitions + * @param {ModdleElement} bpmnDiagram */ - function render(definitions, selectedDiagram) { + function render(definitions, bpmnDiagram) { var visitor = { @@ -57,7 +57,7 @@ export function importBpmnDiagram(diagram, definitions, selectedDiagram, done) { // traverse BPMN 2.0 document model, // starting at definitions - walker.handleDefinitions(definitions, selectedDiagram); + walker.handleDefinitions(definitions, bpmnDiagram); } try { @@ -67,7 +67,7 @@ export function importBpmnDiagram(diagram, definitions, selectedDiagram, done) { eventBus.fire('import.render.start', { definitions: definitions }); - render(definitions, selectedDiagram); + render(definitions, bpmnDiagram); eventBus.fire('import.render.complete', { error: error,