Giter Site home page Giter Site logo

Implement Dart 3 recods about auto_mappr HOT 7 CLOSED

tenhobi avatar tenhobi commented on May 29, 2024
Implement Dart 3 recods

from auto_mappr.

Comments (7)

tenhobi avatar tenhobi commented on May 29, 2024 1

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?

from auto_mappr.

Abdulrasheed1729 avatar Abdulrasheed1729 commented on May 29, 2024 1

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 👍

from auto_mappr.

Abdulrasheed1729 avatar Abdulrasheed1729 commented on May 29, 2024

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?

from auto_mappr.

Abdulrasheed1729 avatar Abdulrasheed1729 commented on May 29, 2024

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.

from auto_mappr.

tenhobi avatar tenhobi commented on May 29, 2024

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.

from auto_mappr.

Abdulrasheed1729 avatar Abdulrasheed1729 commented on May 29, 2024

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.

from auto_mappr.

tenhobi avatar tenhobi commented on May 29, 2024

Will be available in v2

from auto_mappr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.