numen31337 / copy_with_extension

Provides Dart Build System builder for generating copyWith extensions for annotated classes.
https://pub.dev/packages/copy_with_extension_gen
MIT License
74 stars 30 forks source link

Deep nested copy #92

Open tolotrasamuel opened 5 months ago

tolotrasamuel commented 5 months ago

Describe the issue

With the freezed package, I was able to able copy the Company model by changing only the name of the assistant director with one single line.

Company company;

Company newCompany = company.copyWith.director.assistant(name: 'John Smith');

To the best of my knowledge, this is not possible with copy_with_extension , because director is a function .

It will be great if you could add the same feature parity as freezed since you package focus solely on the copy with extension, people expect it to be at least on par with freezed copyWith capability

Environment details

Paste the flutter environment detail.

flutter doctor
flutter --version
3.19.3

Paste the package version.

dependencies:
  copy_with_extension: 5.0.4

To Reproduce Without any library, the following is cumbersome:

Company company;

Company newCompany = company.copyWith(
  director: company.director.copyWith(
    assistant: company.director.assistant.copyWith(
      name: 'John Smith',
    ),
  ),
);

Expected behaviour

With the freezed package, I was able to able copy the Company model by changing only the name of the assistant director with one single line.

Company company;

Company newCompany = company.copyWith.director.assistant(name: 'John Smith');

To the best of my knowledge, this is not possible with copy_with_extension , because director is a function .

It will be great if you could the same feature parity as freezed since you package focus solely on the copy with extension, people expect it to be at least on par with freezed copyWith capability

Additional context

For reference, freezed , freezed uses classes on thecompany.copyWith.director. generated code and overrides the call method, instead of a function

f-person commented 2 months ago

Just came here to write this. I don't really like freezed, so I also solely rely on copy_with_extension to get my copyWith methods. So yeah, this would be awesome indeed (otherwise, the code is really boilerplate-y with nested stuff)!