onAppEventModified method

void onAppEventModified(
  1. FFAppEvent appEvent
)

Update the graph when an app event is modified.

Re-analyzes dependencies and updates edges accordingly.

Implementation

void onAppEventModified(FFAppEvent appEvent) {
  if (!appEvent.hasIdentifier() || appEvent.identifier.key.isEmpty) {
    return;
  }

  final nodeId = NodeIds.appEvent(appEvent.identifier.key);
  final node = graph.getNode(nodeId);
  if (node == null) {
    // Node doesn't exist, treat as an add
    onAppEventAdded(appEvent);
    return;
  }

  // Remove old granular dependencies
  final oldGranularImports =
      node.imports.where(NodeIds.isGranularDependencyNodeId).toList();
  for (final depNodeId in oldGranularImports) {
    graph.removeDependency(nodeId, depNodeId);
    graph.removeIfOrphan(depNodeId);
  }

  // Re-add edges for current state
  if (appEvent.globalHandlerActionComponentIdentifier.key.isNotEmpty) {
    final abNodeId = NodeIds.actionBlock(
      appEvent.globalHandlerActionComponentIdentifier.key,
    );
    if (!graph.hasNode(abNodeId)) {
      graph.addNode(
        DependencyNode(id: abNodeId, type: DependencyNodeType.actionBlock),
      );
    }
    graph.addDependency(nodeId, abNodeId);
  }

  if (appEvent.hasData &&
      appEvent.hasDataTypeParameter() &&
      appEvent.dataTypeParameter.hasDataType() &&
      appEvent.dataTypeParameter.dataType.hasSubType()) {
    final subType = appEvent.dataTypeParameter.dataType.subType;
    if (subType.hasDataStructIdentifier() &&
        subType.dataStructIdentifier.key.isNotEmpty) {
      final dsNodeId = NodeIds.dataStruct(subType.dataStructIdentifier.key);
      if (!graph.hasNode(dsNodeId)) {
        graph.addNode(
          DependencyNode(id: dsNodeId, type: DependencyNodeType.dataStruct),
        );
      }
      graph.addDependency(nodeId, dsNodeId);
    }
    if (subType.hasEnumIdentifier() &&
        subType.enumIdentifier.key.isNotEmpty) {
      final enumNodeId = NodeIds.enumType(subType.enumIdentifier.key);
      if (!graph.hasNode(enumNodeId)) {
        graph.addNode(
          DependencyNode(id: enumNodeId, type: DependencyNodeType.enumType),
        );
      }
      graph.addDependency(nodeId, enumNodeId);
    }
  }
}