flock 0.1.1

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • new58

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.0.1] - 2019/1/8

  • Initial release.

[0.0.2] - 2019/1/8

  • Update readme.

[0.0.3] - 2019/1/8

  • Add basic documents to public interface.

[0.0.4] - 2019/1/9

  • Add Store#get as a shorthand of Store#projectWith

[0.0.5] - 2019/1/9

  • Rename EventStore to Store

[0.0.6] - 2019/1/9

  • Hide Store#replaceEvents from user

[0.0.7] - 2019/1/9

  • Add basic Flutter integration.

[0.0.8] - 2019/1/10

  • Update interface to match Redux better.
  • Add ShakeBack enhancer.
  • Add StoreBuilder interface.

[0.0.9]

  • Rename build in StoreBuilder's params to builder
  • Eliminate rebuilds caused by StoreBuilder

[0.0.10]

  • Add description
  • Rename ShakeBack API

[0.0.11]

  • Add example
  • Update description

[0.0.12]

  • Rename StoreWidget interface
  • Remove Projectable from signature of Projector
  • Remove EventStack, using chronological List instead

[0.1.0]

  • Separate Reducer and Initializer
  • Rename InnerStore to StoreForEnhancer
  • Expose more methods in StoreForEnhancer

[0.1.1]

  • Remove withShakeBack
  • Fix StackOverflow when get Store#cursor
  • Remove unnecessary dependencies.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flock: ^0.1.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flock/flock.dart';
  
Version Uploaded Documentation Archive
0.1.1 Jan 15, 2019 Go to the documentation of flock 0.1.1 Download flock 0.1.1 archive
0.0.12 Jan 11, 2019 Go to the documentation of flock 0.0.12 Download flock 0.0.12 archive
0.0.11 Jan 10, 2019 Go to the documentation of flock 0.0.11 Download flock 0.0.11 archive
0.0.10 Jan 10, 2019 Go to the documentation of flock 0.0.10 Download flock 0.0.10 archive
0.0.9 Jan 10, 2019 Go to the documentation of flock 0.0.9 Download flock 0.0.9 archive
0.0.8 Jan 10, 2019 Go to the documentation of flock 0.0.8 Download flock 0.0.8 archive
0.0.7 Jan 9, 2019 Go to the documentation of flock 0.0.7 Download flock 0.0.7 archive
0.0.6 Jan 9, 2019 Go to the documentation of flock 0.0.6 Download flock 0.0.6 archive
0.0.5 Jan 9, 2019 Go to the documentation of flock 0.0.5 Download flock 0.0.5 archive
0.0.4 Jan 9, 2019 Go to the documentation of flock 0.0.4 Download flock 0.0.4 archive

All 13 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
21
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
58
Learn more about scoring.

We analyzed this package on Jan 15, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.10
  • Flutter: 1.1.7

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Fix lib/src/integration/StoreBuilder.dart. (-0.50 points)

Analysis of lib/src/integration/StoreBuilder.dart reported 1 hint:

line 11 col 25: Use ; instead of {} for empty constructor bodies.

Maintenance suggestions

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use flock.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test
matcher ^0.12.3