updateProps<T extends ControllerMethodPropConsumer<RenderViewModel>> static method

void updateProps<T extends ControllerMethodPropConsumer<RenderViewModel>>(
  1. T? t,
  2. RenderNode node,
  3. VoltronMap? paramsMap
)

Implementation

static void updateProps<T extends ControllerMethodPropConsumer>(
  T? t,
  RenderNode node,
  VoltronMap? paramsMap,
) {
  if (paramsMap == null || t == null) {
    return;
  }

  final propertyName = t.name;
  var provider = sPropsMethodMap[propertyName];
  if (provider == null) {
    provider = t.generateProvider();
    sPropsMethodMap[propertyName] = provider;
  }

  final methodMap = provider.renderMethodMap;
  final props = paramsMap.keySet();
  for (var prop in props) {
    final value = paramsMap.get<Object>(prop);
    var propMethodHolder = methodMap[prop];
    if (propMethodHolder != null) {
      final realValue = checkValueType(value, propMethodHolder.defaultValue);
      try {
        if (realValue != null) {
          Function.apply(propMethodHolder.method, [
            node.renderViewModel,
            realValue,
          ]);
        } else {
          Function.apply(propMethodHolder.method, [
            node.renderViewModel,
            propMethodHolder.defaultValue,
          ]);
        }
      } catch (e) {
        LogUtils.e(
          kTag,
          "update controller($propertyName) prop($prop) to ($value) error:$e",
        );
      }
      if (value is VoltronMap && prop == NodeProps.kStyle) {
        updateProps(t, node, value);
      }
    } else {
      if (value is VoltronMap && prop == NodeProps.kStyle) {
        updateProps(t, node, value);
      } else if (value != null) {
        t.setCustomProp(node, prop, value);
      }
    }
  }
}