dart_mappable icon indicating copy to clipboard operation
dart_mappable copied to clipboard

Ignore big fields on equality

Open CodeDoctorDE opened this issue 1 year ago • 0 comments

Hello, I have currently this classes:

@MappableClass(generateMethods: GenerateMethods.all & ~GenerateMethods.equals)
class GameTable with GameTableMappable {
  final Map<VectorDefinition, TableCell> cells;
  final ItemLocation? background;

  const GameTable({
    this.cells = const {},
    this.background,
  });

  TableCell getCell(VectorDefinition position) =>
      cells[position] ?? TableCell();
}


@MappableClass()
final class WorldState with WorldStateMappable {
  final GameTable table;
  final String tableName;
  final GameInfo info;
  final String? name;
  final Channel id;
  final Map<String, Set<Channel>> teamMembers;
  final FileMetadata metadata;
  final QuokkaData data;
  final List<ChatMessage> messages;

  const WorldState({
    this.name,
    this.table = const GameTable(),
    this.tableName = '',
    this.info = const GameInfo(),
    this.metadata = const FileMetadata(),
    this.teamMembers = const {},
    this.messages = const [],
    this.id = kAuthorityChannel,
    required this.data,
  });
}

The problem now is: cells can be really, really big. The time calculating if cells are the same is very long. How can I only say that cells should be ignored when testing for equality?

The current functionality works when removing the equality operator. The problem now is if I use the class in world state. It also checks for the full map instead of only using the equality operator. How can I fix this?

CodeDoctorDE avatar Oct 01 '24 14:10 CodeDoctorDE