void updateJsonValue(input)

Source

void updateJsonValue(input) {
  if (input is! Map) {
    updateValue(input);
    _json = input;

    String type = _guessType(input);

    String lastType = configs[r"$type"];

    if (lastType != type) {
      configs[r"$type"] = type;
      updateList(r"$type");
    }

    return;
  }

  clearValue();
  JsonDiff.JsonDiffer differ = new JsonDiff.JsonDiffer(
    JSON.encode(_json),
    JSON.encode(input)
  );

  JsonDiff.DiffNode fullDiff = differ.diff();

  void apply(JsonDiff.DiffNode diff, DsaJsonNode node) {
    for (String key in diff.added.keys) {
      var name = NodeNamer.createName(key);
      provider.addNode(
        "${node.path}/${name}",
        buildNodeMap(diff.added[key])
      );
      node.updateList(r"$is");
    }

    for (String key in diff.removed.keys) {
      var name = NodeNamer.createName(key);

      provider.removeNode("${node.path}/${name}");
    }

    for (String key in diff.changed.keys) {
      var name = NodeNamer.createName(key);

      DsaJsonNode child = node.getChild(name);

      if (child == null) {
        child = provider.addNode(
          "${node.path}/${name}",
          buildNodeMap(diff.changed[key][1])
        );
      } else {
        child.updateJsonValue(diff.changed[key][1]);
      }
    }

    for (String key in diff.node.keys) {
      var name = NodeNamer.createName(key);

      DsaJsonNode child = node.getChild(name);

      if (child == null) {
        child = provider.addNode("${node.path}/${name}", buildNodeMap({}));
      }

      apply(diff.node[key], child);
    }
  }

  apply(fullDiff, this);

  _json = input;
}