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

[Question] Using this library with Redux and combine reducers #424

Closed
hillelcoren opened this Issue May 28, 2018 · 4 comments

Comments

Projects
None yet
2 participants
@hillelcoren

hillelcoren commented May 28, 2018

I'm just getting started with an app, I'm trying to use Redux with built_value. The app is working but I've needed to add .toBuilder() in all of the reducers (ie, https://github.com/invoiceninja/flutter-mobile/blob/master/lib/redux/app/app_reducer.dart#L14).

Is a terrible mistake or the right way to do it?

Thanks for your help and the great library!

@davidmorgan

This comment has been minimized.

Collaborator

davidmorgan commented May 28, 2018

Very good question. Yes, there is a better way to do it. Instead of assigning a builder, use the 'replace' method:

    ..companyState1.replace(state.selectedCompanyIndex == 1
        ? companyReducer(state.companyState1, action) : state.companyState1)

This is a bit less typing and a bit more efficient.

@hillelcoren

This comment has been minimized.

hillelcoren commented May 28, 2018

Thank you so much! Can I ask a quick follow up question.

Our API returns a list of objects however to follow Redux best practice we're storing the the data as a map and an array. We're currently first creating maps/lists and then creating the built values, is there a more performant approach?

https://github.com/invoiceninja/flutter-mobile/blob/master/lib/redux/product/product_reducer.dart#L66

Thanks again for your help and the libraries, they're awesome :)

@davidmorgan

This comment has been minimized.

Collaborator

davidmorgan commented May 28, 2018

Similarly, you want ..map.addIterable for the map, and ..list.replace for the list.

Generally you can go via methods on the builders rather than assigning a new builder.

@hillelcoren

This comment has been minimized.

hillelcoren commented May 28, 2018

Perfect, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment