reactive_component 0.1.3-dev.1
reactive_component: ^0.1.3-dev.1 copied to clipboard
A package that supports for creating stream-based reactive components.
ReactiveComponent #
A package that supports for creating stream-based reactive components, designed for simplicity, composability, flexibility.
With ReactiveComponent, it can compose models by taking advantage of Stream's powerful features in a concise codebase. Thus it can be applied to any size of apps, from very small ones to large ones that usually have many complex component models.
It is yet another state management package for Flutter apps. When a ReactiveComponent wraps a domain model, it is described as implementing BLoC design pattern.
A quick example: counter model. #
/// [ReactiveComponent] is a unit that encapsulates its members
/// and publicizes only [Sink]s and [Stream]s.
class _Counter with ReactiveComponent {
_Counter(this._initialCount);
final int _initialCount;
/// A special kind of [StreamSink] with its own single stream listener
/// that handles the event data.
///
/// In current Dart, one can use a lazy initialization technique with "??=",
/// so that it can access the other instance members at its callback functions.
///
/// With "late final" in "null-safety" spec in a future Dart,
/// the notation will be conciser as below,
///
/// '''dart
/// late final increment = VoidReactiveSink((_) {
/// _count.data++;
/// }, disposer: disposer);
/// '''
VoidReactiveSink _increment;
VoidReactiveSink get increment => _increment ??= VoidReactiveSink((_) {
// Increments _count on a increment event is delivered.
_count.data++;
}, disposer: disposer);
/// A [Reactive], [int] data as count state of this counter.
///
/// [Reactive] is a special kind of [StreamController] that holds its latest
/// stream data, and sends that as the first data to any new listener.
///
/// In current Dart, one can use a lazy initialization technique with "??=",
/// so that it can access the other instance members at its callback functions.
///
/// With "late final" in "null-safety" spec in a future Dart,
/// the notation will be conciser as below,
///
/// '''dart
/// late final _count = Reactive<int>(_initialCount, disposer: disposer);
/// '''
Reactive<int> __count;
Reactive<int> get _count =>
__count ??= Reactive<int>(_initialCount, disposer: disposer);
/// Publicize only the stream of [_count] to hide its data mutating
/// and the other behaviors.
/// It's a good point to transform the stream as necessary.
Stream<int> get count => _count.stream;
}
For a complete Flutter counter app example with more detailed comments, see Flutter counter example.
Examples #
There are two examples.
- Flutter Counter
- Composing Firebase
Status #
Both "null safety" and "non null safety" version are available. Null safety versions are published as pre-release version.
Documents and more test code should be added. Some APIs will likely change. More features are planned, such as logging for Sink / Stream, static analysis supports.
Features and bugs #
Please file feature requests and bugs at the issue tracker.