sinew_presentation
StateEffectHandler, EventActionHandler and EffectEmitter: the presentation pattern, with no framework.
A page has state (what it renders) and effects (one-time reactions, such as a snackbar or a navigation), and effects are never state, so a rebuild can't repeat them. These base classes hold that pattern in plain Dart. sinew_riverpod adapts them to Riverpod notifiers.
Features
StateEffectHandler<S, F>for a page with one intent:setState,emitEffect, andstatesandeffectsstreamsEventActionHandler<S, E, A, F>for a page with several intents: the page sends events, a puremapEventToActiondecides the work, andonActiondoes itEffectEmitter<F>: each effect is delivered once, to one listener, and held until there is one
Getting started
dart pub add sinew_presentation
Usage
final class Counter extends StateEffectHandler<CounterState, ReachedTen> {
Counter() : super(const CounterState(0));
void increment() {
setState((state) => CounterState(state.count + 1));
if (state.count == 10) emitEffect(const ReachedTen());
}
}
final counter = Counter();
counter.effects.listen((effect) => print('the counter reached ten'));
counter.states.listen((state) => print('count: ${state.count}'));
The full program is in example/main.dart.
Related packages
Sinew is one architecture for Flutter and Kotlin, released as a set of packages at one version.
Documentation
- Usage docs: sinew.srctool.com
- API reference: pub.dev/documentation/sinew_presentation
- Source and issues: srctool/sinew-dart
- Design and decisions: the Guide
License
Apache 2.0, see LICENSE.
Libraries
- sinew_presentation
- StateEffectHandler, EventActionHandler and EffectEmitter, framework-neutral.