bloc_stream 3.0.0 copy "bloc_stream: ^3.0.0" to clipboard
bloc_stream: ^3.0.0 copied to clipboard

discontinued
outdated

A simple package that helps you to implement the BLoC pattern in your applications.

example/example.dart

import 'package:bloc_stream/bloc_stream.dart';

class CounterBloc extends BlocStream<int> {
  @override
  int get initialValue => 0;

  void increment() {
    subject.add(value + 1);
  }

  void decrement() {
    subject.add(value - 1);
  }
}

class MultiplicationBloc extends BlocStream<int> {
  MultiplicationBloc(CounterBloc counter) : _counter = counter {
    // Bloc has a helper method for cleaning up subscriptions without having to
    // write a boilerplate close() override.
    cancelOnClose(counter.stream.distinct().listen((count) {
      subject.add(_multiply(count));
    }));
  }

  final CounterBloc _counter;

  @override
  int get initialValue => _multiply(_counter.value);

  int _multiply(int count) {
    return count * 3;
  }
}

void main() {
  final counter = CounterBloc();
  final multiplier = MultiplicationBloc(counter);

  // Prints:
  // 0
  // MULTIPLY 0
  // 1
  // 2
  // MULTIPLY 3
  // 3
  // MULTIPLY 6
  // 2
  // MULTIPLY 9
  // 1
  // MULTIPLY 6
  // MULTIPLY 3
  counter.stream.distinct().listen(print);
  multiplier.stream.distinct().listen((i) => print('MULTIPLY $i'));

  counter.increment();
  counter.increment();
  counter.increment();
  counter.decrement();
  counter.decrement();
}
3
likes
0
pub points
3%
popularity

Publisher

verified publishertimsmart.co

A simple package that helps you to implement the BLoC pattern in your applications.

Repository (GitLab)
View/report issues

License

unknown (LICENSE)

Dependencies

meta, rxdart

More

Packages that depend on bloc_stream