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

outdated

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.

Usage #

import 'package:flock/flock.dart';

// Events
class E {}

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

  final String value;
}

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

  final int v;
}

// Store
final store = createStore<E>();

// Your projector

final projector = (int prev, EventStack<E> events, Projectable<E> store) {
  var result = prev ?? 0;
   // notice the events are in reverse chronological order
  for (var event in events) {
    if (event is EB)
      result += event.v;
    else if (event is EA)
      result -= int.tryParse(event.value) ?? 0;
  }
  return result;
};

// In you widget:

store.dispatch(EB(1));

store.subscribe((E e){
  final projection = store.getState(projector);
  // projection will be 1
});

//or

class BW extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return StoreBuilder( 
      build: (BuildContext context, int p) => Text(
            '$p',
            textDirection: TextDirection.ltr,
          ),
      store: store, // receive store from wherever you like
      projector: projector, // you can also provide a method as projector
    );
  }
}


Limits #

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

  • better Flutter integration
  • serialization & time travel support

License #

MIT

0
likes
0
pub points
0%
popularity

Publisher

unverified uploader

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

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on flock