process method

  1. @override
ProcessedArg process(
  1. JsonWidgetRegistry registry,
  2. dynamic arg,
  3. Set<String>? jsonWidgetListenVariables
)
override

Process passed arg into ProcessedArg. The registry is giving functions and variables information context for the processing.

Passed jsonWidgetListenVariables is the information about variables that JsonWidgetData depends on. Passing that should be make the ArgProcessor to stop calculating these variable names. It is treated as a optimization.

ProcessedArg contains info about arg real value and variable names that it depends on.

Implementation

@override
ProcessedArg process(
  JsonWidgetRegistry registry,
  dynamic arg,
  Set<String>? jsonWidgetListenVariables,
) {
  final mapArg = arg as Map;
  final calculateListenVariables = jsonWidgetListenVariables == null;
  final resultListenVariables = jsonWidgetListenVariables ?? <String>{};
  final processedMapArg = {};

  if (_isJsonWidgetData(mapArg)) {
    // The entry has a "type" and one of: "child", "children", "args".  This
    // means the item is most likely a JsonWidgetData class, so we should
    // not process the args yet.  We should wait until the actual
    // JsonWidgetData gets built.
    return ProcessedArg(
        value: arg, jsonWidgetListenVariables: resultListenVariables);
  }

  for (var key in mapArg.keys) {
    final processedKeyArg =
        _processKey(registry, key, jsonWidgetListenVariables);
    final processedValueArg =
        registry.processArgs(mapArg[key], jsonWidgetListenVariables);
    processedMapArg[processedKeyArg.value] = processedValueArg.value;
    if (calculateListenVariables) {
      resultListenVariables
          .addAll(processedKeyArg.jsonWidgetListenVariables.toList());
      resultListenVariables.addAll(
        processedValueArg.jsonWidgetListenVariables.toList(),
      );
    }
  }
  return ProcessedArg(
    value: processedMapArg,
    jsonWidgetListenVariables: resultListenVariables,
  );
}