-
Notifications
You must be signed in to change notification settings - Fork 1
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
Refactor NetworkRequestExecutor
; utilise Unit
; remove need for dummy providers targeting dynamic
types
#503
Conversation
This comment was marked as duplicate.
This comment was marked as duplicate.
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## develop #503 +/- ##
===========================================
+ Coverage 79.58% 84.85% +5.27%
===========================================
Files 114 114
Lines 1195 1195
===========================================
+ Hits 951 1014 +63
+ Misses 244 181 -63
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
NetworkRequestExecutor
; utilise Unit
; remove need for dummy providers targeting dynamic
types
lib/features/opening_hours/data/models/opening_hours_model.dart
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor things :)
Overview:
This PR refactors the
NetworkRequestExecutor
class to improve its readability, maintainability, and testability. It also updates all dependent components to align with the new executor methods.Notably, it also removes the need to provide dummy values for certain
dynamic
types, e.g. for the typeEither<NetworkFailure, dynamic>
, which triggered linter warnings.Changes to
NetworkRequestExecutor
:Added New Typedefs: Introduced
_NetworkRequest<BodyType>
and_ExecutorResult<R>
to avoid repetition.Method Renaming and Refactoring:
call
toexecute
and updated its signature.logResponse
to_logResponse
and slightly simplified its logic.executeAndDiscard
for requests where the response body is not needed.dynamic
types as mentioned in the overview.New Mapping Extensions:
ExecutorMapX
andExecutorMapAllX
to handle mapping of results. The call tomap()
ormapAll()
should be chained after anexecute()
call.mapAll()
is only possible when dealing with executor calls where the expected response body is anIterable
.TaskEither
class in the future.network_request_executor_mapping.dart
, which is a part ofnetwork_request_executor.dart
.Added Documentation: Added doc comments to all methods above.
How it affects code
Take a look at how code is affected by this refactor:
await
keyword in code means noasync
tag is needed in the method signature.call
, the return type ofexecute
can be easily accessed with your preferred code editor. This aims to improve DX and fits well alongside the new similarly named methodexecuteAndDiscard
.call
, the Dart formatter will automatically format chained method calls in a way that better conveys what's happening.Other changes
Updates in Other Components:
EnvironmentRemoteDataSource
,OpeningHoursRemoteDataSource
,ProductRemoteDataSource
, etc., to use the new executor methods.map()
/mapAll()
extensions removeeither_extensions.dart
as a dependency to these files.OpeningHoursRepository
(and Impl); replaced with new classOpeningHoursModel
to better align with the rest of the codebase.OpeningHoursRemoteDataSource.getOpeningHours()
to return an entity rather than a generated DTO class to better align the rest of the codebase.Test Updates: Updated tests to align with the new executor methods.
Removed a barrel file that wasn't supposed to exist in feature Opening Hours
ticket_remote_data_source.dart
: Moved mapper method out of the large chain of calls to improve readability.Why This is Necessary:
Readability: Method renaming and new typedefs make the code easier to understand.
Testability: The
executeAndDiscard
method simplifies testing for requests where the response body is not important.Maintainability: Improved documentation and more descriptive method names make the code easier to maintain.
Please review and let me know if any changes are required.