flock 0.7.1

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.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.

[0.3.0]

  • Update interface
  • Add UseCase

[0.3.2]

  • Add ObservableStateLifecycle integration

[0.4.0]

  • Update observeStore interface

[0.4.1]

  • Use active_observers

[0.5.0]

  • Update file structure.

[0.6.0]

  • Update observeStore

[0.7.0]

  • Improve performance
  • Remove unnecessary dependency
  • Store#subscribe can only be cancelled by returned Unsubscribe function
  • Add projectToStream
  • Remove observeStore
  • Apply enhancers from right to left like Redux
  • Extract Projectable type
  • Projector now accept Projectable as the third parameter
  • Make publish return published event.
  • Add batchSubscribe, publishFilter and printEvents enhancers
  • Rename withUseCase to withSideEffect
  • Remove generics for event on Store
  • Add use cases context.

Use this package as a library

1. Depend on it

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


dependencies:
  flock: ^0.7.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub 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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
31
Health:
Code health derived from static analysis. [more]
98
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
63
Learn more about scoring.

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

  • Dart: 2.5.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.2

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Fix lib/base/create_store.dart. (-0.50 points)

Analysis of lib/base/create_store.dart reported 1 hint:

line 102 col 3: Avoid return types on setters.

Fix lib/contexts/use_case.dart. (-0.50 points)

Analysis of lib/contexts/use_case.dart reported 1 hint:

line 95 col 13: Close instances of dart.core.Sink.

Fix lib/integration/project_to_stream.dart. (-0.50 points)

Analysis of lib/integration/project_to_stream.dart reported 1 hint:

line 9 col 11: Close instances of dart.core.Sink.

Fix lib/integration/store_builder.dart. (-0.50 points)

Analysis of lib/integration/store_builder.dart reported 1 hint:

line 10 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 filename patterns include main.dart, example.dart, and flock.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
collection ^1.14.11 1.14.11 1.14.12
flutter 0.0.0
uuid ^2.0.2 2.0.2
Transitive dependencies
charcode 1.1.2
convert 2.1.1
crypto 2.1.3
meta 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