Skip to main content

sinew_presentation 1.1.0 copy "sinew_presentation: ^1.1.0" to clipboard
sinew_presentation: ^1.1.0 copied to clipboard

StateEffectHandler, EventActionHandler and EffectEmitter, framework-neutral.

example/main.dart

// ignore_for_file: avoid_print

import 'package:sinew_presentation/sinew_presentation.dart';

// region counter
/// The state a page renders.
final class CounterState {
  const CounterState(this.count);

  final int count;
}

/// A one-time reaction: never state, so a rebuild can't repeat it.
final class ReachedTen {
  const ReachedTen();
}

/// A page with one intent: state in, state and effects out.
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());
  }
}
// endregion

Future<void> main() async {
  final counter = Counter();
  counter.effects.listen((effect) => print('effect: the counter reached ten'));
  counter.states.listen((state) => print('count: ${state.count}'));

  for (var i = 0; i < 10; i++) {
    counter.increment();
    await Future<void>.delayed(Duration.zero); // let the page see each state
  }
  counter.dispose();
}
0
likes
160
points
208
downloads

Documentation

Documentation
API reference

Publisher

verified publishersrctool.com

Weekly Downloads

StateEffectHandler, EventActionHandler and EffectEmitter, framework-neutral.

Repository (GitHub)
View/report issues
Contributing

Topics

#state-management #architecture #mvvm

License

Apache-2.0 (license)

Dependencies

meta

More

Packages that depend on sinew_presentation