RgaList<T>.fromMap constructor
Deserializes a sequence.
Always pass this device's own replicaId when the instance will be
edited. Without it the list deserializes with an empty (or, for
legacy payloads, the creator's) identity — two devices editing copies
of the same document then mint COLLIDING node ids, and one device's
concurrent edits are deterministically discarded on merge.
Implementation
factory RgaList.fromMap(
Map<String, dynamic> map,
T Function(dynamic raw) decoder, {
String? replicaId,
}) {
final nodes = <String, RgaNode<T>>{};
var maxCounter = (map['counter'] as num?)?.toInt() ?? 0;
for (final raw in (map['nodes'] as List? ?? const [])) {
final m = Map<String, dynamic>.from(raw as Map);
final node = RgaNode<T>(
replicaId: m['r'] as String,
counter: (m['c'] as num).toInt(),
origin: m['o'] as String?,
value: decoder(m['v']),
deleted: m['d'] as bool? ?? false,
);
nodes[node.id] = node;
if (node.counter > maxCounter) maxCounter = node.counter;
}
return RgaList._(replicaId ?? (map['replicaId'] as String? ?? ''), nodes, maxCounter);
}