-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Remove RxDart dependency from bloc package #821
Conversation
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.
Just had a few minor comments but overall awesome PR! Given the recent changes to rxdart (migration to extensions on Stream) I think this makes a lot of sense. Thanks so much for opening this 💯
I am not sure atm, but using
What I mean:
|
@felangel is there a test case for this? If not, I think that would be a good addition ;) |
93632b2
to
f92d137
Compare
PR contains problems. Changed status to @tenhobi you are right. Solution with I propose to add test to cover this issue in separate PR. It will be very useful.
@tenhobi thank you. Good catch 👍 |
db319fa
to
8d31770
Compare
Implemented Added tests which cover |
@mmozhaiskyi thanks for your efforts! I have a few concerns about this approach and would love to hear your thoughts:
Thoughts? (cc @brianegan) |
Was just messing around on my own branch and managed to simplify the implementation a bit more (I think). What do y'all think? |
@felangel Thank you for your feedback. Your proposal is awesome and useful. Really, we don’t need full implementation of Changes:
|
Co-Authored-By: Felix Angelov <felangelov@gmail.com>
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.
LGTM 💯
Thanks for your patience and for incorporating all of the feedback so quickly 👍
@jorgecoca, @brianegan thoughts? It ended up being almost identical to Brian's PR which was by far the most simple approach.
Wait, my bad -- was coding too quickly. My implementation has a big problem: You can't listen to the test('close does not emit new states over the state stream', () {
final expectedStates = [equals(''), emitsDone];
expectLater(
simpleBloc,
emitsInOrder(expectedStates),
);
expectLater(
simpleBloc,
emitsInOrder(expectedStates),
);
simpleBloc.close();
}); This gets a bit hairy: I changed that state StreamController from a The cause of that issue in the tests? Events were added to the The test('should map single event to correct state', () {
final expectedStates = ['', 'data'];
expectLater(
simpleBloc,
emitsInOrder(expectedStates),
);
expectLater(
simpleBloc,
emitsInOrder(expectedStates),
);
expectLater(
simpleBloc,
emitsInOrder(expectedStates),
);
simpleBloc.add('event');
}); |
Updated my branch with those changes! |
@@ -10,7 +10,7 @@ import '../bloc.dart'; | |||
/// {@endtemplate} | |||
abstract class Bloc<Event, State> extends Stream<State> implements Sink<Event> { | |||
final _eventController = StreamController<Event>.broadcast(); | |||
final _stateController = StreamController<State>(); | |||
final _stateController = StreamController<State>.broadcast(); |
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.
Looks good! I'd just make sure to add the test to catch this bug as well.
Going to merge and will apply the testing updates right after. Thanks everyone! |
Codecov Report
@@ Coverage Diff @@
## master #821 +/- ##
=======================================
Coverage ? 100%
=======================================
Files ? 16
Lines ? 247
Branches ? 0
=======================================
Hits ? 247
Misses ? 0
Partials ? 0
Continue to review full report at Codecov.
|
Hi @felangel @mozhaiskyi So if I understand it right, though BehaviorSubject was removed from bloc/cubit but some other mechanism was implemented to keep it work as it was with BehaviorSubject?
Log:
|
Hi @sla-000 this is working as expected and has been this way since bloc v6.0.0. See https://bloclibrary.dev/#/migration?id=%e2%9d%97bloc-does-not-emit-last-state-on-subscription for more information. |
Hi @felangel Thanks for quick response and explanation! This creates boilerplate code. Is there any chance this ever will be changed back to BehaviorSubject or something similar? I understand you are trying to keep code pure with as little dependencies as possible but may be it is simplified too much and we are throwing the baby out with bath water 🙂 |
@sla-000 have you considered using a shared repository to implement communication between the blocks? This way it might simplify your use case of needing to cope with the duality of the bloc behaviour. Note that |
@maximveksler Could you provide some example of that shared repository, please? |
Status
READY
Breaking Changes
NO
Description
BloC is architecture library which used as the foundation of the application. In my opinion it should be independent of any other libraries like RxDart.
Rx code was used only in two places inside bloc package.
PublishSubject
,BehaviorSubject
replaced with twoStreamController
. Also added variable for storing current state which called_currentState
)RxDart
because package is enable as a test dependency)