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

Possible to generate merge and apply methods too? #13

Open
stargazing-dino opened this issue Nov 7, 2019 · 1 comment
Open

Possible to generate merge and apply methods too? #13

stargazing-dino opened this issue Nov 7, 2019 · 1 comment

Comments

@stargazing-dino
Copy link

stargazing-dino commented Nov 7, 2019

Hi! First off, I love this package. It has solved so many problems for me.

My current use case is when a user signs in, I have their configuration for the app saved in Firebase. If it's their first time signing in, I have to populate it with reasonable empty fields. This is what that currently looks like:

// Configuration extends $Configuration and also uses json_serializable
//
// Inside document.get().then((snapshot) =>
final empty = Configuration.empty();

if (snapshot.exists) {
  final configuration = Configuration.fromJson(snapshot.data);

  await configurationDocument.setData(
    Configuration(
      primaryColor: configuration.primaryColor ?? empty.primaryColor,
      // A lot more fields . . .
    ).toJson(),
  );
} else {
  await configurationDocument.setData(empty.toJson());
}

With merge I think could just say something like:

await configurationDocument.setData(
  configuration.merge(empty).toJson()
);
@spkersten
Copy link
Owner

This seems like a useful feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants