toIncrementalJson method

String toIncrementalJson(
  1. ChangedEvent e, [
  2. String? classname
])

Produce a JSON-format string representing the changes in the most recent Transaction. This writes out JSON for a model, but recording only changes in the given Transaction, with the addition of the "incremental" property to mark it as different from a complete model. Instead of the "nodeDataArray" property (and "linkDataArray" property for GraphLinksModels), this will have "inserted...", "modified...", and "removed..." properties that are non-empty Arrays.

The "modifiedNodeData" Array holds JavaScript objects. The "insertedNodeKeys" and "removedNodeKeys" Arrays hold keys (numbers or strings) of data, not whole objects, that have been added and/or deleted. The "modelData" property holds the Model#modelData object, if it was modified.

Note that it is entirely plausible for the same object be in or referenced by all three Arrays, because a single Transaction can include adding a node, modifying it, and removing it.

The purpose of this method is to make it easier to send incremental changes to the server/database, instead of sending the whole model. Whereas it has always been easy to perform "batch" updates or "file saves":

  myDiagram.addModelChangedListener(e => {
    if (e.isTransactionFinished) {
      var json = e.model.toJson();
      // save the whole model upon each transaction completion or undo/redo
      ... send to server/database ...
    }
  });

You can now easily send "incremental" updates:

  myDiagram.addModelChangedListener(e => {
    if (e.isTransactionFinished) {
      var json = e.model.toIncrementalJson(e);
      // record each Transaction as a JSON-format string
      ... send to server/database ...
    }
  });

Note that these incremental changes include the results of undo and redo operations. Also, when you might call #applyIncrementalJson, you will need to disable your Changed listener, so that it does not send spurious changes to your database during the process of apply incremental changes from the database.

For GraphLinksModels, this method requires that GraphLinksModel#linkKeyProperty is not an empty string. The incremental JSON for GraphLinksModels will include "modifiedLinkData", "insertedLinkKeys", and "removedLinkKeys" properties that are non-empty Arrays.

The same restrictions on data property names and data property values applies to this method as it does to #toJson. @param {ChangedEvent} e a Transaction ChangedEvent for which ChangedEvent#isTransactionFinished is true @param {string=} classname for the written model, defaults to the name of the class of the model @return {string} @since 1.6

Implementation

_i2.String toIncrementalJson(
  _i3.ChangedEvent e, [
  _i2.String? classname,
]) =>
    _i4.callMethod(
      this,
      'toIncrementalJson',
      [
        e,
        classname ?? _i5.undefined,
      ],
    );