flock 0.7.1 copy "flock: ^0.7.1" to clipboard
flock: ^0.7.1 copied to clipboard

Coordinate Flutter widgets' states with event sourcing. What if Redux store contains no reducers, no state but only actions?

flock #

Build Status

Coordinate Flutter widgets' states with event sourcing.

Inspired by Redux.

Design #

Usage #

import 'package:flock/flock.dart';

// Events
class E {}

class Minus extends E {
  Minus(this.value);

  final String value;
}

class Add extends E {
  Add(this.v);

  final int v;
}

// Store
final store = createStore();

// In you widget:
class BW extends StatelessWidget {
  int sum(int prev, Iterable<E> events, Projectable store) {
    var result = prev ?? 0;
    for (var event in events) {
      if (event is Add)
        result += event.v;
      else if (event is Minus)
        result -= int.tryParse(event.value) ?? 0;
    }
    return result;
  }

  @override
  Widget build(BuildContext context) {
    return StoreBuilder( 
      builder: (BuildContext context, int p) => Text(
            '$p',
            textDirection: TextDirection.ltr,
          ),
      store: store, // use store from wherever you like
      projector: sum
    );
  }
}


Limits #

This is still an early WIP. The future plan includes:

  • better Flutter integration
  • serialization & time travel support

License #

MIT

0
likes
25
points
32
downloads

Publisher

unverified uploader

Weekly Downloads

Coordinate Flutter widgets' states with event sourcing. What if Redux store contains no reducers, no state but only actions?

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

collection, flutter, uuid

More

Packages that depend on flock