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

Add default mapper in BaseQueryCubit #23

Open
pdenert opened this issue Mar 19, 2024 · 6 comments
Open

Add default mapper in BaseQueryCubit #23

pdenert opened this issue Mar 19, 2024 · 6 comments
Assignees

Comments

@pdenert
Copy link
Contributor

pdenert commented Mar 19, 2024

In many situations QueryCubit does not need to map the returned data, it just needs to pass it on. So we can cover this situation with the default mapper to avoid writing this boilerplate code:

@override
T? map(T? data) => data;
@mkucharski17
Copy link

I agree with @pdenert. I saw many times map implementation without any mapping.

@michalina-majewska
Copy link
Contributor

@pdenert @mkucharski17

The default implementation can be used only when TData == TOut (so we can pass on the data value). I'd say it's already provided by SimpleArgsQueryCubit and SimpleQueryCubit as they both have TData == TOut and TOut map(TOut data) => data;.

My suggestion is, we start using extends on SimpleArgsQueryCubit and SimpleQueryCubit instead of ArgsQueryCubit and QueryCubit when TData == TOut. One difference is that we have to pass the request function as a constructor argument instead of overriding it.

Did I miss a case in which this doesn't work?

@zltnDC
Copy link
Collaborator

zltnDC commented Jun 19, 2024

SimpleCubits were developed for hooks. We can extract them from use_query_cubit.dart and change the parameters to named parameters for better readability. Also, mention them in README.md.

@michalina-majewska
Copy link
Contributor

Okay, will do

@mkucharski17
Copy link

TBH I feel like I do not have enough knowledge for this discussion. I have never used this package. I just wanted to say, that I saw many times in Activy where @pdenert uses this package occurrences of the map method which does not do any mapping like code below.

T? map(T? data) => data

It seems like redundant code that could be implemented as a default behavior. I hope @pdenert can answer your questions @michalina-majewska.

@pdenert
Copy link
Contributor Author

pdenert commented Jun 19, 2024

Yeah, usage of the Simple*QueryCubits will work for me. Changes suggested by @zltnDC also ‘ll made it more readable, but we need to keep in mind that, this will be a breaking change, so the version should be appropriately bumped

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

4 participants