Getting XML within Modeler Plugin

I’m ultimately trying to get access to the model XML from within a Modeler plugin, but every time I inject a ‘bpmnjs’ object (with the vain hope of finding a saveXML function) the modeler crashes when I create a new BPMN model.

If I take out the injection of this service it starts up OK.

What am I doing wrong, and more importantly where can I find some definitive documentation on what is valid to be injected?

Thanks

Example code is as follows:

'use strict';

var http = require('http');

function InsurtechUploadPlugin(bpmnjs, eventBus, elementRegistry, editorActions, canvas, modeling) {
  this._elementRegistry = elementRegistry;
  this._modeling = modeling;
  this._canvas = canvas;
  this._eventBus = eventBus;
  this._bpmnjs = bpmnjs;

  var self = this;

  eventBus.on('shape.added', function(event) {
      console.log('A shape was added to the diagram!');
    });

  editorActions.register({
    uploadModel: function() {
      self.doTheWork();
    }
  });

}


InsurtechUploadPlugin.prototype.doTheWork = function() {
  console.log("Do the work ... ", this._bpmnjs);

  http.get({
        host: 'www.google.co.uk',
        path: '/'
    }, function(response) {

        var body = '';
        response.on('data', function(d) {
            body += d;
        });
        response.on('end', function() {

            // console.log("->", body);

        });
    });

};


InsurtechUploadPlugin.$inject = [ 'eventBus', 'elementRegistry', 'editorActions', 'canvas', 'modeling', 'bpmnjs' ];

module.exports = {
    __init__: ['insurtechUploadPlugin'],
    insurtechUploadPlugin: ['type', InsurtechUploadPlugin]
};

Doh. I didn’t appreciate the injection process was positionally dependant, but makes sense as there’s no typing information on the injection. Matching up the injection to the usage has fixed things, per:

function InsurtechUploadPlugin(bpmnjs, eventBus, elementRegistry, editorActions, canvas, modeling) {

and

InsurtechUploadPlugin.$inject = [ 'bpmnjs', 'eventBus', 'elementRegistry', 'editorActions', 'canvas', 'modeling' ];

1 Like