# all files / bpmn-js/lib/features/modeling/behavior/ UnsetDefaultFlowBehavior.js

100% Statements 14/14
100% Branches 4/4
100% Functions 3/3
100% Lines 14/14

    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

    1189×

    1189×
    148×
    148×
    148×

    148×
    4×

    1×

    1×

    148×
    42×

    106×
    106×

    106×
     import inherits from 'inherits';

    import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';

    import {
      getBusinessObject,
      is
    } from '../../../util/ModelUtil';

    /**
     * A behavior that unsets the Default property of
     * sequence flow source on element delete, if the
     * removed element is the Gateway or Task's default flow.
     *
     * @param {EventBus} eventBus
     * @param {Modeling} modeling
     */
    export default function DeleteSequenceFlowBehavior(eventBus, modeling) {

      CommandInterceptor.call(this, eventBus);

      this.preExecute('connection.delete', function(event) {
        var context = event.context,
            connection = context.connection,
            source = connection.source;

        if (isDefaultFlow(connection, source)) {
          modeling.updateProperties(source, {
            'default': null
          });
        }
      });
    }

    inherits(DeleteSequenceFlowBehavior, CommandInterceptor);

    DeleteSequenceFlowBehavior.$inject = [
      'eventBus',
      'modeling'
    ];

    // helpers //////////////////////

    function isDefaultFlow(connection, source) {

      if (!is(connection, 'bpmn:SequenceFlow')) {
        return false;
      }

      var sourceBo = getBusinessObject(source),
          sequenceFlow = getBusinessObject(connection);

      return sourceBo.get('default') === sequenceFlow;
    }