# all files / Github/diagram-js/lib/features/change-support/ ChangeSupport.js

100% Statements 17/17
100% Branches 6/6
100% Functions 6/6
100% Lines 17/17

    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

    1128×

    3757×

    3757×
    3273×

    3757×
    484×

    3273×

    1128×

    1236×

    1236×
    3757×

    1236×

    1128×
    2202×

    1128×
    1070×

    1×

     import {
      getType as getElementType
    } from '../../util/Elements';

    /**
     * Adds change support to the diagram, including
     *
     * <ul>
     *   <li>redrawing shapes and connections on change</li>
     * </ul>
     *
     * @param {EventBus} eventBus
     * @param {Canvas} canvas
     * @param {ElementRegistry} elementRegistry
     * @param {GraphicsFactory} graphicsFactory
     */
    export default function ChangeSupport(
        eventBus, canvas, elementRegistry,
        graphicsFactory) {

      // redraw shapes / connections on change

      eventBus.on('element.changed', function(event) {

        var element = event.element;

        // element might have been deleted and replaced by new element with same ID
        // thus check for parent of element except for root element
        if (element.parent || element === canvas.getRootElement()) {
          event.gfx = elementRegistry.getGraphics(element);
        }

        // shape + gfx may have been deleted
        if (!event.gfx) {
          return;
        }

        eventBus.fire(getElementType(element) + '.changed', event);
      });

      eventBus.on('elements.changed', function(event) {

        var elements = event.elements;

        elements.forEach(function(e) {
          eventBus.fire('element.changed', { element: e });
        });

        graphicsFactory.updateContainments(elements);
      });

      eventBus.on('shape.changed', function(event) {
        graphicsFactory.update('shape', event.element, event.gfx);
      });

      eventBus.on('connection.changed', function(event) {
        graphicsFactory.update('connection', event.element, event.gfx);
      });
    }

    ChangeSupport.$inject = [
      'eventBus',
      'canvas',
      'elementRegistry',
      'graphicsFactory'
    ];