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

refactor(bloc): add isClosed to Closable interface #3066

Merged
merged 2 commits into from Dec 18, 2021
Merged

refactor(bloc): add isClosed to Closable interface #3066

merged 2 commits into from Dec 18, 2021

Conversation

purplenoodlesoop
Copy link
Contributor

@purplenoodlesoop purplenoodlesoop commented Dec 15, 2021

Closes #3065

Status

READY

Breaking Changes

NO

Description

There are three main changes done in the following PR. All of them are targeted to extend the recent "core interfaces" update to further apply the Interfaces Segregation and Dependency Inversion principles.

Refer to #3065

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

/// An interface for hooks of the [BlocBase].
///
/// Contains the `onChange` and `onError` hooks.
abstract class BlocBaseHooks<State> {
Copy link
Owner

@felangel felangel Dec 15, 2021

Choose a reason for hiding this comment

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

What's the benefit of introducing this interface? I don't like the name hooks because it can be confused with flutter_hooks and I also would prefer not to define interfaces unnecessarily. Is there a concrete use-case you had in mind which required operating on this interface specifically?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's the benefit of introducing this interface?

The main benefits align with those that ISP and DIP brings — other object can implement the lifecycle calls more easily, other object interested only in lifecycle calls can depend only on desired parts, making code more loosely coupled.

I don't like the name hooks because it can be confused with flutter_hooks and I also would prefer not to define interfaces unnecessarily.

Totally agree, the name can be confusing. LifecycleObserver sounds good!

Is there a concrete use-case you had in mind which required operating on this interface specifically?

Yes, I was implementing a custom, project-specific version of Bloc that needed some of the "on.." methods, and had to either just hard-code them in the implementation, or extend/implement the BlocBase, but not all methods was desired.

Those interfaces would allow to unify lifecycle calls.

On the other hand, I agree that non-essential interfaces can be redundant and open to discard them if you think that it's too much :)

Also, what constitutes a hook? I would expect onCreate, onClose, etc. to also be included.

I agree, they should be also included if we decide to keep the interfaces!

@felangel felangel added pkg:bloc This issue is related to the bloc package refactor Refactor an existing implementation labels Dec 15, 2021
@felangel felangel added this to In progress in bloc via automation Dec 15, 2021
@felangel felangel changed the title Add more interfaces, update the Closable interface & apply DIP refactor(bloc): add isClosed to Closable interface Dec 18, 2021
@codecov
Copy link

codecov bot commented Dec 18, 2021

Codecov Report

Merging #3066 (1946930) into master (77bb1ce) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##            master     #3066    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           30         8    -22     
  Lines          721       192   -529     
==========================================
- Hits           721       192   -529     
Impacted Files Coverage Δ
packages/bloc/lib/src/bloc_base.dart 100.00% <100.00%> (ø)
packages/bloc_concurrency/lib/src/restartable.dart
...ackages/hydrated_bloc/lib/src/hydrated_cipher.dart
...lutter_bloc/lib/src/multi_repository_provider.dart
packages/hydrated_bloc/lib/src/hydrated_bloc.dart
packages/bloc_concurrency/lib/src/sequential.dart
packages/flutter_bloc/lib/src/bloc_selector.dart
packages/flutter_bloc/lib/src/bloc_listener.dart
packages/bloc_concurrency/lib/src/droppable.dart
packages/replay_bloc/lib/src/change_stack.dart
... and 13 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 77bb1ce...1946930. Read the comment docs.

@felangel felangel merged commit d61220c into felangel:master Dec 18, 2021
bloc automation moved this from In progress to Done Dec 18, 2021
@felangel felangel mentioned this pull request Dec 29, 2021
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:bloc This issue is related to the bloc package refactor Refactor an existing implementation
Projects
bloc
  
Done
Development

Successfully merging this pull request may close these issues.

refactor: further apply the DIP and ISP principles
2 participants