defaultMergeModes function

List<Mode> defaultMergeModes(
  1. List<Mode> storyModes,
  2. List<Mode> scenarioModes
)

The default function to merge modes of a story and a scenario. It puts the modes of the scenario first, and then adds the modes of the story that are not already defined in the scenario.

Implementation

List<Mode> defaultMergeModes(
  List<Mode> storyModes,
  List<Mode> scenarioModes,
) {
  final scenarioModesTypes = scenarioModes
      .map((mode) => mode.runtimeType)
      .toSet();

  final filteredStoryModes = storyModes.where(
    (mode) => !scenarioModesTypes.contains(mode.runtimeType),
  );

  return [
    ...scenarioModes,
    ...filteredStoryModes,
  ];
}