fromJson static method

Operation fromJson(
  1. dynamic data
)

Creates new Operation from JSON payload.

Implementation

static Operation fromJson(data) {
  final map = new Map<String, dynamic>.from(data);
  if (map.containsKey(Operation.insertKey)) {
    final String text = map[Operation.insertKey];
    return new Operation._(Operation.insertKey, text.length, text, map[Operation.attributesKey]);
  } else if (map.containsKey(Operation.deleteKey)) {
    final int? length = map[Operation.deleteKey];
    return new Operation._(Operation.deleteKey, length, '', null);
  } else if (map.containsKey(Operation.retainKey)) {
    final int? length = map[Operation.retainKey];
    return new Operation._(Operation.retainKey, length, '', map[Operation.attributesKey]);
  }
  throw new ArgumentError.value(data, 'Invalid data for Delta operation.');
}