Hooking into Events


#1

Hi there,

question seems to be rather dull but I can’t get the event bus to call my callback on the shape.create event. This is what I’ve tried:

Option 1 - Create a module (preferred way):

I created a module with this descriptor:

module.exports = {
  __init__: [ 'listener' ],
  listener: [ 'type', require('./Listener.js') ]
};

… with following code …


function Listener(eventBus) {
  eventBus.on('shape.create', 999999, function(event) {
    console.log('Did you just try to create something?!');
  });
}

Listener.$inject = [ 'eventBus' ];

module.exports = Listener;

This module was passed as the first of the aditionalModules in the modelerOptions. This didn’t work.

Option 2 - Hook after startup:

Straightforward:

/* ... code ... */
this.modeler = new BpmnModeler(this.modelerOptions);
this.modeler.get('eventBus').on('shape.create', 999999, function(event) {
  console.log('Did you just try to create something?!');
});

This didn’t work neither.

What am I doing wrong?


#2

Who should fire shape.create?


#3

Try shape.added. It’s called every time a shape was added to the canvas.


#4

I don’t know who should fire it, but by the example for custom modeling rules I guessed this event existed and gets fired whenever a shape is added.


#5

Thanks, that was the event I was looking for! How good I have found out about this for myself? Is there any place they’re all listed?


#6

shape.create is not an event but a command. You can find it here. Commands !== Events. :wink: