Skip to content

Commit

Permalink
refactor(bloc)!: introduce EmittableStateStreamableSource (#4311)
Browse files Browse the repository at this point in the history
  • Loading branch information
felangel authored Jan 1, 2025
1 parent faada70 commit ed7b27c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
12 changes: 12 additions & 0 deletions .github/actions/dart_package/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ inputs:
codecov_token:
required: true
description: The Codecov token used to upload coverage
collect_coverage:
required: false
default: "true"
description: Whether to collect code coverage
collect_score:
required: false
default: "true"
description: Whether to collect the pana score
concurrency:
required: false
default: "4"
Expand Down Expand Up @@ -69,13 +77,15 @@ runs:
dart test -j ${{inputs.concurrency}} --coverage=coverage && dart pub global run coverage:format_coverage --lcov --in=coverage --out=coverage/lcov.info --packages=.dart_tool/package_config.json --report-on=${{inputs.report_on}} --check-ignore
- name: 📦 Detect Package Name
if: inputs.collect_coverage == 'true'
env:
PACKAGE_PATH: ${{ inputs.working_directory}}
id: package
shell: ${{ inputs.shell }}
run: echo "name=${PACKAGE_PATH##*/}" >> $GITHUB_OUTPUT

- name: ⬆️ Upload Coverage
if: inputs.collect_coverage == 'true'
uses: codecov/codecov-action@v4
env:
PACKAGE_PATH: ${{ inputs.working_directory}}
Expand All @@ -84,13 +94,15 @@ runs:
token: ${{ inputs.codecov_token }}

- name: 📊 Verify Coverage
if: inputs.collect_coverage == 'true'
uses: VeryGoodOpenSource/very_good_coverage@v3
with:
path: ${{inputs.working_directory}}/coverage/lcov.info
exclude: ${{inputs.coverage_excludes}}
min_coverage: ${{inputs.min_coverage}}

- name: 💯 Verify Pub Score
if: inputs.collect_score == 'true'
working-directory: ${{ inputs.working_directory }}
shell: ${{ inputs.shell }}
run: |
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ jobs:
codecov_token: ${{ secrets.CODECOV_TOKEN }}
working_directory: packages/${{ matrix.package }}
min_coverage: 100
# TODO: remove once bloc v9 is published
# https://github.com/dart-lang/pana/issues/1254
collect_score: false

flutter_package_checks:
needs: changes
Expand All @@ -238,6 +241,9 @@ jobs:
codecov_token: ${{ secrets.CODECOV_TOKEN }}
working_directory: packages/${{ matrix.package }}
min_coverage: 100
# TODO: remove once bloc v9 is published
# https://github.com/dart-lang/pana/issues/1254
collect_score: false

angular_dart_example_checks:
needs: changes
Expand Down
6 changes: 5 additions & 1 deletion packages/bloc/lib/src/bloc_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,16 @@ abstract class ErrorSink implements Closable {
void addError(Object error, [StackTrace? stackTrace]);
}

/// A [StateStreamableSource] that can emit new states.
abstract class EmittableStateStreamableSource<State>
implements StateStreamableSource<State>, Emittable<State> {}

/// {@template bloc_base}
/// An interface for the core functionality implemented by
/// both [Bloc] and [Cubit].
/// {@endtemplate}
abstract class BlocBase<State>
implements StateStreamableSource<State>, Emittable<State>, ErrorSink {
implements EmittableStateStreamableSource<State>, ErrorSink {
/// {@macro bloc_base}
BlocBase(this._state) {
// ignore: invalid_use_of_protected_member
Expand Down
4 changes: 2 additions & 2 deletions packages/bloc_test/lib/src/bloc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ import 'package:test/test.dart' as test;
///
/// [configuring tags]: https://github.com/dart-lang/test/blob/master/pkgs/test/doc/configuration.md#configuring-tags
@isTest
void blocTest<B extends BlocBase<State>, State>(
void blocTest<B extends EmittableStateStreamableSource<State>, State>(
String description, {
required B Function() build,
FutureOr<void> Function()? setUp,
Expand Down Expand Up @@ -173,7 +173,7 @@ void blocTest<B extends BlocBase<State>, State>(
/// Internal [blocTest] runner which is only visible for testing.
/// This should never be used directly -- please use [blocTest] instead.
@visibleForTesting
Future<void> testBloc<B extends BlocBase<State>, State>({
Future<void> testBloc<B extends EmittableStateStreamableSource<State>, State>({
required B Function() build,
FutureOr<void> Function()? setUp,
State Function()? seed,
Expand Down
6 changes: 3 additions & 3 deletions packages/bloc_test/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ topics: [bloc, state-management, test]
funding: [https://github.com/sponsors/felangel]

environment:
sdk: ">=2.12.0 <4.0.0"
sdk: ">=2.14.0 <4.0.0"

dependencies:
bloc: ^8.1.1
diff_match_patch: ^0.4.1
meta: ^1.3.0
mocktail: ">=0.2.0 <2.0.0"
mocktail: ^1.0.0
test: ^1.16.0

dev_dependencies:
rxdart: ^0.27.2
rxdart: ^0.28.0

screenshots:
- description: The bloc test package logo.
Expand Down

0 comments on commit ed7b27c

Please sign in to comment.