YMapEvent.fromJson constructor
YMapEvent.fromJson(
- Object? json_
Returns a new instance from a JSON value. May throw if the value does not have the expected structure.
Implementation
factory YMapEvent.fromJson(Object? json_) {
final json = json_ is Map
? _spec.fields.map((f) => json_[f.label]).toList(growable: false)
: json_;
return switch (json) {
[final target, final keys, final path] ||
(final target, final keys, final path) =>
YMapEvent(
target: YMap.fromJson(target),
keys: (keys! as Iterable)
.map((e) => (() {
final l = e is Map
? List.generate(2, (i) => e[i.toString()],
growable: false)
: e;
return switch (l) {
[final v0, final v1] || (final v0, final v1) => (
v0 is String ? v0 : (v0! as ParsedString).value,
YMapDelta.fromJson(v1),
),
_ => throw Exception('Invalid JSON $e')
};
})())
.toList(),
path: (path! as Iterable).map(EventPathItem.fromJson).toList(),
),
_ => throw Exception('Invalid JSON $json_')
};
}