addMissingState function

TTGraphData addMissingState(
  1. TTGraphData graphData
)

Implementation

TTGraphData addMissingState(TTGraphData graphData) {
  final updatedGraphData = graphData;
  final now = DateTime.now().millisecondsSinceEpoch;

  for (final soul in graphData.entries) {
    if (soul.value == null) {
      continue;
    }

    var node = soul.value;

    var meta = (node?.nodeMetaData = node.nodeMetaData ?? TTNodeMeta());
    meta?.key = soul.key;
    var state = (meta?.forward = meta.forward ?? TTNodeState());

    for (final key in node!.keys) {
      if (key == '_') {
        continue;
      }
      state?[key] = state[key] ?? now;
    }
    updatedGraphData[soul.key] = node;
  }

  return updatedGraphData;
}