Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Dart 3 recods #58

Closed
Tracked by #103
tenhobi opened this issue Apr 28, 2023 · 7 comments · Fixed by #116
Closed
Tracked by #103

Implement Dart 3 recods #58

tenhobi opened this issue Apr 28, 2023 · 7 comments · Fixed by #116
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers
Milestone

Comments

@tenhobi
Copy link
Member

tenhobi commented Apr 28, 2023

Implement support for record types.

Note: we might merge it even before we have Dart 3 since the analyzer already can know the record type.

@tenhobi tenhobi added enhancement New feature or request good first issue Good for newcomers labels Apr 28, 2023
@Abdulrasheed1729
Copy link

Abdulrasheed1729 commented May 3, 2023

To implement for the Dart 3 records, in my opinion, I think it would be better to first convert it to a map first for it to work, for example like a toMap() extension function,

final record1 = (2, 'hello', true);
print(record1.toMap()) // prints {'$1': 2, '$2' : 'hello', '$3' : true}

but it seems difficult to implement. And it is almost impossible according to what is here.
Or is there something I'm missing?

@tenhobi
Copy link
Member Author

tenhobi commented May 4, 2023

I haven't looked much into it, but I initially thought we could get positional and named things out of it, similar to the constructor, and do something about it?

@Abdulrasheed1729
Copy link

Oh, yes, thanks, I just found out there is RecordType 😄 in the anlayzer library with the namedFields and positionalFields getters, I will try to get something out of that 👍

@Abdulrasheed1729
Copy link

Abdulrasheed1729 commented May 6, 2023

I've been trying to mess around with some things, what if we have the type Record use as a primitive type 🤔? Like what is in this extension.

extension DartTypeExtension on DartType {
  bool get isPrimitiveType =>
      isDartCoreNum ||
      isDartCoreInt ||
      isDartCoreDouble ||
      isDartCoreString ||
      isDartCoreBool ||
      isDartCoreEnum ||
      isDartCoreSymbol ||
      isDartCoreRecord;
}

And have something like this

@AutoMappr([
  MapType<RecordHolderDto, RecordHolder>(),
])
class Mappr extends $Mappr {}

class RecordHolder {
  final Record value;

  RecordHolder(this.value);
}

class RecordHolderDto {
  final Record value;

  RecordHolderDto(this.value);
}

I still doubt if this is right, but I just want show it, before I create a PR.

@tenhobi
Copy link
Member Author

tenhobi commented May 7, 2023

I think the difference between primitives and iterable/map right now is that we pass a primitive just like that, and we map each part of iterable/map.

Meaning in the Iterable I can have List<UserDto> -> List<User>, in Map, I can have Map<KeyDto, ValueDto> -> Map<Key, Value>, and in Record, I can have (UserDto, AddressDto, school: SchoolDto, ...) -> (User, Address, school: School, ...).

I am not sure how the records mapping should work exactly either because we didn't use it yet. :D That is what this issue is about -- do research and probably do it similarly to list/map mappings. It's for sure a tricky issue to do.

@Abdulrasheed1729
Copy link

Yes, it is quite tricky one to implement. I will make more findings and try to imitate that of map/list.
Thanks for the feedback.

@tenhobi tenhobi mentioned this issue Jul 20, 2023
5 tasks
@petrnymsa petrnymsa added this to the auto_mappr_NEXT milestone Aug 25, 2023
@tenhobi tenhobi self-assigned this Aug 25, 2023
This was referenced Aug 25, 2023
@tenhobi tenhobi linked a pull request Aug 29, 2023 that will close this issue
@tenhobi
Copy link
Member Author

tenhobi commented Sep 4, 2023

Will be available in v2

@tenhobi tenhobi closed this as completed Sep 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants