love 0.2.0 copy "love: ^0.2.0" to clipboard
love: ^0.2.0 copied to clipboard

A state management library that is declarative, predictable and elegant.

example/example.dart

import 'package:love/love.dart';

// typedef CounterState = int;

abstract class CounterEvent {}
class Increment implements CounterEvent {}
class Decrement implements CounterEvent {}

void main() async {
  
  final counterSystem = System<int, CounterEvent>
    .create(initialState: 0)
    .on<Increment>(
      reduce: (state, event) => state + 1,
      effect: (state, event, dispatch) async {
        await Future<void>.delayed(const Duration(seconds: 3));
        dispatch(Decrement());
      },
    )
    .on<Decrement>(
      reduce: (state, event) => state - 1,
    )
    .log()
    .reactState(
      effect: (state, dispatch) {
        print('Simulate persistence save call with state: $state');
      },
    )
    .onRun(effect: (initialState, dispatch) {
      dispatch(Increment());
      return null;
    },);
  
  final disposer = counterSystem.run();

  await Future<void>.delayed(const Duration(seconds: 6));

  disposer();
}
4
likes
120
pub points
0%
popularity

Publisher

unverified uploader

A state management library that is declarative, predictable and elegant.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

meta, typedef_equals

More

Packages that depend on love