insert method

Delta insert(
  1. int index,
  2. Object data
)

Inserts data in this document at specified index.

The data parameter can be either a String or an instance of EmbeddableObject.

Applies heuristic rules before modifying this document and produces a change event with its source set to ChangeSource.local.

Returns an instance of Delta actually composed into this document.

Implementation

Delta insert(int index, Object data) {
  assert(index >= 0);
  if (data is String) {
    if (data.isEmpty) return Delta();
  } else {
    assert(data is EmbeddableObject);
    data = (data as EmbeddableObject).toJson();
  }

  final change = heuristics.applyInsertRules(this, index, data);
  compose(change, ChangeSource.local);
  return change;
}