forwardUnconsumedProps function

  1. @Deprecated('This implementation does not filter DOM props correctly. Use forwardUnconsumedPropsV2 instead.')
void forwardUnconsumedProps(
  1. Map props, {
  2. bool omitReactProps = true,
  3. bool onlyCopyDomProps = false,
  4. Iterable? keysToOmit,
  5. Iterable<Iterable>? keySetsToOmit,
  6. required Map propsToUpdate,
})

Adds unconsumed props to a passed in Map reference (propsToUpdate).

Based upon configuration, the function will overlook props that are not meant to be passed on, such as non-DOM props or specified values.

DEPRECATED: Use forwardUnconsumedPropsV2 instead.

Implementation

@Deprecated('This implementation does not filter DOM props correctly. Use forwardUnconsumedPropsV2 instead.')
void forwardUnconsumedProps(Map props, {
  bool omitReactProps = true,
  bool onlyCopyDomProps = false,
  Iterable? keysToOmit,
  Iterable<Iterable>? keySetsToOmit,
  required Map propsToUpdate,
}) {
  if (onlyCopyDomProps) {
    for (final key in props.keys) {
      if ((key is String && (key.startsWith('aria-') ||
          key.startsWith('data-'))) ||
          _validDomProps.contains(key)) {
        propsToUpdate[key] = props[key];
      }
    }
    return;
  }

  for (final key in props.keys) {
    if (keysToOmit != null && keysToOmit.contains(key)) continue;

    if (keySetsToOmit != null && keySetsToOmit.isNotEmpty) {
      /// If the passed in value of [keySetsToOmit] comes from
      /// [addUnconsumedProps], there should only be a single index.
      /// Consequently, this case exists to give the opportunity for the loop
      /// to continue without initiating another loop (which is less
      /// performant than `.first.contains()`).
      /// TODO: further optimize this by identifying the best looping / data structure
      if (keySetsToOmit.first.contains(key)) continue;

      if (keySetsToOmit.length > 1) {
        bool shouldContinue = false;
        for (final keySet in keySetsToOmit) {
          if (keySet.contains(key)) {
            shouldContinue = true;
            break;
          }
        }

        if (shouldContinue) continue;
      }
    }

    if (omitReactProps && const ['key', 'ref', 'children'].contains(key)) continue;

    propsToUpdate[key] = props[key];
  }
}