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

feat: Add freezed support to feature_brick #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AdamBuchweitz
Copy link

Brick

  • model
  • feature_brick
  • app_ui
  • service
  • service_package

Status

READY

Breaking Changes

NO

Description

I used Freezed in conjunction with BLoC, and this commit adjusts the templates to support that. This change is purely additive in that nothing changes whatsoever if you do choose to use Freezed. If you do use Freezed, you don't need Equatable so I dropped that.

The most significant change is that you can no longer part everything, since the _event and _state files already part with their generated code. Therefore you need to import them as you would a standard file.

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)
  • 🛠️ Bug fix (non-breaking change which fixes an issue)
  • ❌ Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 Code refactor
  • ✅ Build configuration change
  • 📝 Documentation
  • 🗑️ Chore

@AdamBuchweitz AdamBuchweitz deleted the branch LukeMoody01:master July 1, 2022 17:36
@AdamBuchweitz AdamBuchweitz deleted the master branch July 1, 2022 17:36
@LukeMoody01
Copy link
Owner

Hey @AdamBuchweitz 👋

Thanks for having a look into this! Did you want to go over the changes for this PR?

@AdamBuchweitz AdamBuchweitz restored the master branch July 5, 2022 14:54
@AdamBuchweitz
Copy link
Author

Oh dang, whoops. I renamed branch to main, not realized that would affect this PR. Sorry about that!

@AdamBuchweitz AdamBuchweitz reopened this Jul 5, 2022
@LukeMoody01 LukeMoody01 self-assigned this Jul 7, 2022
@LukeMoody01
Copy link
Owner

Oh dang, whoops. I renamed branch to main, not realized that would affect this PR. Sorry about that!

No problem! Thanks again for opening this. I will take a look later today!

Copy link
Owner

@LukeMoody01 LukeMoody01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First off, thanks again for looking into this @AdamBuchweitz!
(Sorry it took a while to get to this! Crazy week 😁)

It's looking good, but I think ideally the generated (.g) files should also come with the brick so that the developer does not need to run any other generation.
For reference, you can see the model brick and see the .g files generated with it.

I am happy to look into it from here if you need it!

@AdamBuchweitz
Copy link
Author

Just to make sure I understand what you're asking: you would prefer me to make the brick, then run build_runner to generate the "_state.freezed.dart" and "_event.freezed.dart" files, then inside each of those generated files replace each of the 92 instances of the feature name with {{feature_name.pascalCase()/snakeCase()}}. Is that correct? This is what I have done.

This seems like an odd request for a few reasons. Firstly, whenever the Freezed package changes the code it generates, this brick will not match that new output without us maintaining it here as well. Secondly, anyone wanting to use the Freezed option will already be accustomed to generating code. Lastly, I doubt anyone will use this brick as it is without customizing it, in which case they will need to run build_runner anyway. Again, it seems odd, but I don't mind conforming to your repo standards.

@LukeMoody01
Copy link
Owner

Just to make sure I understand what you're asking: you would prefer me to make the brick, then run build_runner to generate the "_state.freezed.dart" and "_event.freezed.dart" files, then inside each of those generated files replace each of the 92 instances of the feature name with {{feature_name.pascalCase()/snakeCase()}}. Is that correct? This is what I have done.

This seems like an odd request for a few reasons. Firstly, whenever the Freezed package changes the code it generates, this brick will not match that new output without us maintaining it here as well. Secondly, anyone wanting to use the Freezed option will already be accustomed to generating code. Lastly, I doubt anyone will use this brick as it is without customizing it, in which case they will need to run build_runner anyway. Again, it seems odd, but I don't mind conforming to your repo standards.

I've had a think about it, and I agree with what you've mentioned. If the developer is wanting to use freezed then generating that code just seems like the better option when talking about freezed bloc (Doing this would not make sense for smaller bricks like model).

In this case, I'll have another review in a couple hours and get back to you!

Thanks again @AdamBuchweitz!

Copy link
Owner

@LukeMoody01 LukeMoody01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything else is looking good!

I can do my previous suggestion/comment as it wont take long. Thanks for this!

final isBloc = stateManagement == 'bloc';
final isCubit = stateManagement == 'cubit';
final isProvider = stateManagement == 'provider';
final isRiverpod = stateManagement == 'riverpod';
final isNone = !isBloc && !isCubit && !isProvider && !isRiverpod;

bool useFreezed = false;
if (isBloc) {
useFreezed = context.logger.confirm(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To save developers from more questions, I am thinking of changing this question into a logger.chooseOne to reduce the amount of questions.

So the question would contain the values (Equatable, Freezed, None) - This would only have Freezed as an option if the state management is bloc.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that idea!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wording is a bit tricky on the question, but I think these changes accomplish your idea.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Will take a look later this week!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just following up - do you need anything else from me?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @AdamBuchweitz, Nope! It's all good. I have just been very busy with client work 😅 I will get to this sometime this week!

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

Successfully merging this pull request may close these issues.

None yet

2 participants