Skip to content

Allow some Record introspection #2168

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

Closed
cedvdb opened this issue Mar 26, 2022 · 0 comments
Closed

Allow some Record introspection #2168

cedvdb opened this issue Mar 26, 2022 · 0 comments
Labels
feature Proposed language feature that solves one or more problems

Comments

@cedvdb
Copy link

cedvdb commented Mar 26, 2022

The idea is to have a way to find undefined state

Something like this:

typedef BunnyRecord = PartialRecord<Bunny>; // allows 0 fields in Record
class Bunny {
  final bool isCute;
  final String? name;
  
  Bunny copyWith( BunnyRecord fields) {
    return Bunny(
      isCute: fields.hasPropertyDefined(BunnyRecord.properties.isCute) ? fields.isCute : this.isCute,
      name: fields.hasPropertyDefined(BunnyRecord.properties.name)  ? fields.name : this.name,
    );
  }
}

Admitedly this #140 is be a better solution in the case of copy with but not in other cases like serialization

   final  a = jsonEncode(<BunnyRecord>(isCute: true)); // {'isCute': true }
   final b = jsonEncode(<BunnyRecord>(isCute: true, name: null)); // {'isCute': true, 'name' : null }

The difference between a and b here becomes apparent when you send the json serialization as a database entry update.

@cedvdb cedvdb added the feature Proposed language feature that solves one or more problems label Mar 26, 2022
@cedvdb cedvdb changed the title Allow Record introspection Allow some Record introspection Mar 26, 2022
@cedvdb cedvdb closed this as completed Mar 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Proposed language feature that solves one or more problems
Projects
None yet
Development

No branches or pull requests

1 participant