changedFieldNames function

List<String> changedFieldNames(
  1. Iterable<String> fieldNames,
  2. Map<String, String> markers,
  3. Map<String, Object?> stored,
  4. Map<String, Object?> candidate,
  5. Iterable<String> patched,
)

What changedFields() reports for one proposed update (05 ยง2.2), as the platform's changedFieldNames and the emulator's: the named top-level fields whose stored value differs from the candidate's, by deep JSON equality, absent and null alike. Pass both images as the rule reads them (record and newRecord). A writeOnly or serverOnly field counts as changed whenever the patch names it (patched), whatever its value. System fields are never named.

Implementation

List<String> changedFieldNames(
  Iterable<String> fieldNames,
  Map<String, String> markers,
  Map<String, Object?> stored,
  Map<String, Object?> candidate,
  Iterable<String> patched,
) {
  final named = patched.toSet();
  return [
    for (final name in fieldNames)
      if (markers[name] == 'writeOnly' || markers[name] == 'serverOnly'
          ? named.contains(name)
          : !_sameValue(stored[name], candidate[name]))
        name,
  ];
}