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

Make LogInterceptor constant #2375

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

Conversation

bambinoua
Copy link

Just add the const keyword for LogInterceptor constructor and make all fields final for using it as default parameter.

New Pull Request Checklist

  • I have read the Documentation
  • I have searched for a similar pull request in the project and found none
  • I have updated this branch with the latest main branch to avoid conflicts (via merge from master or rebase)
  • I have added the required tests to prove the fix/feature I'm adding
  • I have updated the documentation (if necessary)
  • I have run the tests without failures
  • I have updated the CHANGELOG.md in the corresponding package

@bambinoua bambinoua requested a review from a team as a code owner February 6, 2025 11:18
@kuhnroyal
Copy link
Member

While I agree with this and immutability in general, this is a breaking change.

@AlexV525
Copy link
Member

I personally disagree with the changes because:

  1. The interceptor was designed to be mutable because you can trigger these switches in the runtime for flexibility such as developing a log panel.
  2. Changes are breaking change.

@bambinoua
Copy link
Author

1. The interceptor was designed to be mutable because you can trigger these switches in the runtime for flexibility such as developing a log panel.

Erm.. I hard imaging how the developer will mutate flags of LogInterceptor on runtime..

final dio = Dio()..interceptors.add(LogInterceptor());
// Somewhere on runtime
if (doesUserWantToChangeRequestHeaderVisibility) {
  final logInterceptors = dio.interceptors.whereType<LogInterceptor>();
  if (logInterceptors.length == 1) {
    logInterceptors[0].requestHeader = true;
  }
}

I can imagine this code:

final dio = Dio()..interceptors.add(LogInterceptor(
  requestHeader: kIsWeb && kDebugMode,
));

As I understand this is a simple logger which intends just to trace requests/responses on development. It just a similar to print. If user need to format the message with data, color or whatever he just creates another printer.

P.S. But it's just a suggestion, all is up to you. :) I just noticed that the Interceptor class has a const constructor and decided why do not apply it for LogInterceptor.

@AlexV525
Copy link
Member

Erm.. I hard imaging how the developer will mutate flags of LogInterceptor on runtime..

https://github.com/odinsam/OdinPlugin/blob/747389200711d85df89f82b178c3e60d5cd0961e/odindio/lib/odindio.dart#L13

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

Successfully merging this pull request may close these issues.

3 participants