fsoft_diff_patch 0.1.1 copy "fsoft_diff_patch: ^0.1.1" to clipboard
fsoft_diff_patch: ^0.1.1 copied to clipboard

Deep compare two objects and produces a diffData to transform object1 to object2

example/main.dart

import 'dart:convert';

import 'package:fsoft_diff_patch/fsoft_diff_patch.dart';

void main() {
  final a = {
    "a": 1,
    "b": 2,
    "c": {
      "d": 3,
      "e": 4,
      "f": {
        "g": 5,
        "h": 6,
      },
    },
  };
  final b = {
    "a": 1,
    // "b": 2, // b is deleted
    "c": {
      "d": 9, // d is changed
      "e": 4,
      "f": {
        "g": 5,
        "h": 7, // h is changed
        "i": 10, // i is added
      },
    },
  };
  // diff a and b and create a diffData object
  final diffData = diff(a, b);
  // print diffData in the console
  print("DIFF DATA\n${json.encode(diffData)}");
  // apply diffData to a and create a new object
  final patchedObj = patch(a, diffData);
  // print patched_a in the console
  print("\n\nPATCHED OBJ\n${json.encode(patchedObj)}");
  // check if patched_a is equal to b
  print("\n\nSAME OBJECT: ${json.encode(patchedObj) == json.encode(b)}");
}
3
likes
160
points
222
downloads

Publisher

unverified uploader

Weekly Downloads

Deep compare two objects and produces a diffData to transform object1 to object2

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

More

Packages that depend on fsoft_diff_patch