ex_bloc 0.2.4

  • Readme
  • Changelog
  • Example
  • Installing
  • new68

ex_bloc #

ExBloc provide simple way to organize bloc middleware and dispatch events.

Usage #

Import #

import 'package:ex_bloc/ex_bloc.dart';

Get ExStore #

final store = ExStore.instance;

Simple state #

class TestState {
  final bool afterInitial;

  const TestState({this.afterInitial});
  factory TestState.initial() {
    return const TestState(afterInitial: false);
  }
}

Simple bloc #

ExBloc does not contain business logic.

class TestBloc extends ExBloc<TestEvent, TestState> {

  @override
  TestState get initialState => TestState.initial();
}

Event #

ExEvent provide business logic and payload

ExStore provide ability to dispatch other events or get other states.

class TestEvent extends ExEvent<TestState, TestBloc> {
  @override
  Stream<TestState> call(ExStore store, TestBloc bloc) async* {
    yield TestState(afterInitial: true);
  }
}

Dispatch events #

store.dispatch(TestEvent());

or

TestEvent().dispatch();

Get state from ExStore #

final store = ExStore.instance;
final testState = store.getState<TestState>();

Reselect usage #

Reselect can be used if needed

final testStateSelector = (ExStore store) => store.getState<TestState>();

final afterInitialSelector = createSelector1(
    testStateSelector,
    (TestState testState) => testState.afterInitial,
);

0.2.3 #

  • Add initialEvents for bloc

0.2.3 #

  • Add initialEvents for bloc

0.2.2 #

  • Update readme

0.2.1 #

  • Minor changes

0.2.0 #

  • Critical state fix
  • Remove ServiceModel interface

0.1.13 #

  • Update changelog

0.1.12 #

  • Update changelog

0.1.11 #

  • Update changelog

0.1.10 #

  • Update readme

0.1.9 #

  • Update readme

0.1.8 #

  • Update readme

0.1.7 #

  • Update readme

0.1.6 #

  • Update readme

0.1.5 #

  • Minor changes

0.1.4 #

  • Update readme and license

0.1.3 #

  • Minor changes

0.1.2 #

  • Remove Flutter dependencies

0.1.1 #

  • Minor changes

0.1.0 #

  • Dev Preview 1

0.0.3 #

  • Add EmptyServiceModel

0.0.2 #

  • Fix description

0.0.1 #

  • Initial release

example/example.dart

import 'package:ex_bloc/ex_bloc.dart';

main() async {
  final store = ExStore.instance;
  final bloc = TestBloc();
  print('afterInitial: ${bloc.state.afterInitial}');
  store.dispatch(TestEvent()); // or TestEvent().dispatch();
  await Future.delayed(Duration(seconds: 1));
  print('afterInitial: ${bloc.state.afterInitial}');
  store.getState<TestState>();
}

class TestState {
  final bool afterInitial;

  const TestState({this.afterInitial});
  factory TestState.initial() {
    return const TestState(afterInitial: false);
  }
}

class TestEvent extends ExEvent<TestState, TestBloc> {
  @override
  Stream<TestState> call(
      ExStore store, TestBloc bloc) async* {
    yield TestState(afterInitial: true);
  }
}

class TestBloc extends ExBloc<TestEvent, TestState> {

  @override
  TestState get initialState => TestState.initial();
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  ex_bloc: ^0.2.4

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:ex_bloc/ex_bloc.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
37
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
68
Learn more about scoring.

We analyzed this package on Dec 13, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.1+4

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
bloc ^2.0.0 2.0.0 3.0.0-dev.1
Transitive dependencies
meta 1.1.8
rxdart 0.22.6 0.23.1
Dev dependencies
effective_dart ^1.1.1
mockito ^4.0.0
test >=1.3.0 <2.0.0
test_coverage ^0.2.0