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 to extend Stream<State> #572

Merged
merged 3 commits into from
Oct 14, 2019
Merged

Refactor Bloc to extend Stream<State> #572

merged 3 commits into from
Oct 14, 2019

Conversation

felangel
Copy link
Owner

@felangel felangel commented Oct 13, 2019

Status

READY

Breaking Changes

YES

Description

Refactor Bloc to extend Stream<State>

bloc.state.listen(print);

becomes

bloc.listen(print);

Rename currentState to state

bloc.currentState

becomes

bloc.state

Todos

  • Tests
  • Documentation (will be added in a separate PR to avoid confusion before the update is published)
  • Examples

Impact to Remaining Code Base

  • Breaking change to the bloc API which will require a major version bump + updates to flutter_bloc and angular_bloc

@felangel felangel added the enhancement New feature or request label Oct 13, 2019
@felangel felangel requested a review from jorgecoca October 13, 2019 03:02
@felangel felangel self-assigned this Oct 13, 2019
@felangel
Copy link
Owner Author

@brianegan can you take a look? I'm planning to open a separate PR to implement Sink<Event> 👍

@codecov
Copy link

codecov bot commented Oct 13, 2019

Codecov Report

Merging #572 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   dart-lang/linter#572   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          11     11           
  Lines         184    186    +2     
=====================================
+ Hits          184    186    +2
Impacted Files Coverage Δ
packages/bloc/lib/src/bloc.dart 100% <100%> (ø) ⬆️

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 aabcd04...c83d751. Read the comment docs.

Copy link

@brianegan brianegan left a comment

Choose a reason for hiding this comment

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

Some of the broadcast stream bits can be removed! Other than that, I think it's quite nice -- especially accessing state inside the mapEventToState methods :)

@felangel
Copy link
Owner Author

Thanks for the feedback @brianegan. Can you please re-review? 😄

Copy link

@brianegan brianegan left a comment

Choose a reason for hiding this comment

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

From a code perspective, looks good to me!

Copy link
Collaborator

@jorgecoca jorgecoca left a comment

Choose a reason for hiding this comment

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

Big fan of the new API! Thank @brianegan for the feedback, and all your help! 💯

@felangel felangel marked this pull request as ready for review October 14, 2019 17:13
@felangel felangel merged commit c9b6674 into master Oct 14, 2019
@felangel felangel deleted the bloc-extends-stream branch October 14, 2019 17:22
@larssn
Copy link

larssn commented Oct 18, 2019

Ouch, could you please notify of breaking changes before pushing big stuff like this? Thanks

@larssn
Copy link

larssn commented Oct 18, 2019

Maybe introduce a temporary get currentState => state;until people have had a chance to switch over. Our code has 1000+ errors since getting this new release. 😅

@bigworld12
Copy link

@larssn well, it had a major version pump, so you shouldn't have gotten this via the usual pub get

@tenhobi
Copy link
Collaborator

tenhobi commented Oct 18, 2019

@larssn according to semver: v0.x.y should not be considered as stable. Keep it in mind for other packages you use as well.

Btw. first major release v1.0.0 is coming #572 !

@larssn
Copy link

larssn commented Oct 18, 2019

@bigworld12
Going from 0.15.x to 0.16.x is a minor version bump.
Dart is using the standard {major}.{minor}.{bugfix}, see https://dart.dev/tools/pub/versioning

@tenhobi You're right, but semver is only respected by some package authors, and not others. I haven't seen mention that this package was not fit for production, or in alpha, for that matter.

In fact, there's a forum thread entitled "Are you using bloc in production". I know the BMW guys are using it in production, because they're stating so in that thread.

The API has changed a few times now. This time was a bit harder to swallow that the last one, as this conflicts with the lint rule dart(close_sinks):

Example:
Doing stuff like final authBloc = Provider.of<AuthenticationBloc>(context); will now complain about authBloc being a stream that should be closed.

I hope I'm not coming off as angry, because that's not the case. I still consider the package essential for complex state management. 👍🏻

@tenhobi
Copy link
Collaborator

tenhobi commented Oct 18, 2019

@larssn In the link you provided, there is mentioned this: 😃

Although semantic versioning doesn’t promise any compatibility between versions prior to 1.0.0, the Dart community convention is to treat those versions semantically as well. The interpretation of each number is just shifted down one slot: going from 0.1.2 to 0.2.0 indicates a breaking change, going to 0.1.3 indicates a new feature, and going to 0.1.2+1 indicates a change that doesn’t affect the public API.

If the package was updated from 0.15.x to 0.16.x (dunno if it was, that's what I see in your post) then it is concidered as a major change by Dart.

Check caret syntax, it should work with ^ as this: ^0.15.2 is equivalent to '>=0.15.2 <0.16.0'.

@larssn
Copy link

larssn commented Oct 18, 2019

Lol, well, that certainly sounds different from standard semver then. 😅

Can't believe I missed that! So Dart is something like {super_major}.{major}.{minor}+{bugfix}.

@felangel
Copy link
Owner Author

@larssn sorry for any inconvenience but as everyone else stated you should not have automatically gotten the update unless you are always using latest and for 0.x.x versions the minor version is treated like the major version. Also it was impossible to avoid a breaking change because the state variable went from being a Stream to a value so I thought it made more sense to make state/currentState a breaking change to make it clear that people had to do some renaming whereas dispose/dispatch are deprecated so you have until 1.0.0 to refactor those. Hope that helps 👍

@larssn
Copy link

larssn commented Oct 18, 2019

@felangel Thanks, I've sorted out our pubspec! 🙂

Any idea how we deal with the lint issue I mentioned above?

@brianegan
Copy link

@felangel @larssn I think that's actually a bug with the linter package, although it might be a difficult one to fix. I'd recommend folks contribute examples to this issue: dart-lang/sdk#57882

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants