all files / Github/bpmn-js/lib/features/modeling/behavior/ BoundaryEventBehavior.js

100% Statements 20/20
100% Branches 13/13
100% Functions 6/6
100% Lines 20/20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68                                  1128×     211× 55×         1128× 204× 204× 204×   204×                   1128× 78× 78×   78×                            
import inherits from 'inherits';
 
import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
 
import { is } from '../../../util/ModelUtil';
 
import {
  filter,
  forEach
} from 'min-dash';
 
 
/**
 * BPMN specific boundary event behavior
 */
export default function BoundaryEventBehavior(eventBus, modeling) {
 
  CommandInterceptor.call(this, eventBus);
 
  function getBoundaryEvents(element) {
    return filter(element.attachers, function(attacher) {
      return is(attacher, 'bpmn:BoundaryEvent');
    });
  }
 
  // remove after connecting to event-based gateway
  this.postExecute('connection.create', function(event) {
    var source = event.context.source,
        target = event.context.target,
        boundaryEvents = getBoundaryEvents(target);
 
    if (
      is(source, 'bpmn:EventBasedGateway') &&
      is(target, 'bpmn:ReceiveTask') &&
      boundaryEvents.length > 0
    ) {
      modeling.removeElements(boundaryEvents);
    }
 
  });
 
  // remove after replacing connected gateway with event-based gateway
  this.postExecute('connection.reconnectStart', function(event) {
    var oldSource = event.context.oldSource,
        newSource = event.context.newSource;
 
    if (is(oldSource, 'bpmn:Gateway') &&
        is(newSource, 'bpmn:EventBasedGateway')) {
      forEach(newSource.outgoing, function(connection) {
        var target = connection.target,
            attachedboundaryEvents = getBoundaryEvents(target);
 
        if (is(target, 'bpmn:ReceiveTask') &&
            attachedboundaryEvents.length > 0) {
          modeling.removeElements(attachedboundaryEvents);
        }
      });
    }
  });
}
 
BoundaryEventBehavior.$inject = [
  'eventBus',
  'modeling'
];
 
inherits(BoundaryEventBehavior, CommandInterceptor);