patchbayJsonEquals function
Structural equality for two decoded JSON values.
== on maps and lists is identity in Dart, so a declared {"a": 1} would
never match an equal object the App just built. Numbers compare by value, so
a JSON 1 matches a 1.0 the consumer computed — the wire cannot tell an
operator which one they typed.
Implementation
bool patchbayJsonEquals(Object? left, Object? right) {
if (left is Map<Object?, Object?>) {
if (right is! Map<Object?, Object?> || left.length != right.length) {
return false;
}
for (final Object? key in left.keys) {
if (!right.containsKey(key)) return false;
if (!patchbayJsonEquals(left[key], right[key])) return false;
}
return true;
}
if (left is List<Object?>) {
if (right is! List<Object?> || left.length != right.length) return false;
for (var index = 0; index < left.length; index += 1) {
if (!patchbayJsonEquals(left[index], right[index])) return false;
}
return true;
}
return left == right;
}