built_reducer 0.6.0

  • Readme
  • Changelog
  • Installing
  • new50

Generates actions and a reducer from a set of pure functions.

Install #

To use [built_reducer], you will need your typical [build_runner]/code-generator setup.
First, install [build_runner] and [built_reducer] by adding them to your pubspec.yaml file:

# pubspec.yaml
dependencies:
  reducer:

dev_dependencies:
  build_runner:
  built_reducer:

This install three packages:

  • build_runner, the tool to run code-generators
  • [built_reducer], the code generator
  • reducer, a package containing base types for [built_reducer].

Usage #

import 'package:meta/meta.dart';
import 'package:reducer/reducer.dart';

part 'counter.g.dart';

@immutable
class CounterState {
  final int count;
  const CounterState(this.count);
}

class CounterReducer extends Reducer<CounterState, CounterAction>
    with _CounterReducer {
  const CounterReducer();

  CounterState add(CounterState previousState, {@required int value}) {
    return CounterState(previousState.count + value);
  }

  CounterState reset(CounterState previousState) {
    return CounterState(0);
  }
}

From there, to generate the missing <Name>Action, _<Name>Reducer and the action classes, you have two possibilities:

  • flutter pub run build_runner build, if your package depends on Flutter
  • pub run build_runner build otherwise

Then use the reducer from the actions :

var state = CounterState(0);
const reducer = CounterReducer();
state = reducer(state, const CounterAddAction(value: 5));
state = reducer(state, const CounterResetAction());

Resulting file #

You have a result in the example folder.

Why using a reducer instead of methods directly. #

Since each call is represented with an instance, you have more possibilities :

  • Reproducing a sequence of calls.
  • Adding middlewares
  • Serializing calls
  • Redux

0.6.0 #

  • Reducer methods aren't static anymore.

0.5.2 #

  • Added const constructors to actions.

0.5.1 #

  • Updated doc

0.5.0 #

  • Initial version

Use this package as a library

1. Depend on it

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


dependencies:
  built_reducer: ^0.6.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:built_reducer/built_reducer.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
1
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
50
Learn more about scoring.

We analyzed this package on Jul 3, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13

Analysis suggestions

Package not compatible with SDK flutter

Because it is not compatible with any of the supported runtimes: flutter-native, flutter-web

Package not compatible with runtime flutter-native on android

Because of the import of dart:mirrors via the import chain package:built_reducer/built_reducer.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/type_checker.dartdart:mirrors

Package not compatible with runtime flutter-native on ios

Because of the import of dart:mirrors via the import chain package:built_reducer/built_reducer.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/type_checker.dartdart:mirrors

Package not compatible with runtime flutter-native on linux

Because of the import of dart:mirrors via the import chain package:built_reducer/built_reducer.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/type_checker.dartdart:mirrors

Package not compatible with runtime flutter-native on macos

Because of the import of dart:mirrors via the import chain package:built_reducer/built_reducer.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/type_checker.dartdart:mirrors

Package not compatible with runtime flutter-native on windows

Because of the import of dart:mirrors via the import chain package:built_reducer/built_reducer.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/type_checker.dartdart:mirrors

Package not compatible with runtime flutter-web on web

Because of the import of dart:io via the import chain package:built_reducer/built_reducer.dartpackage:dart_style/dart_style.dartpackage:dart_style/src/exceptions.dartpackage:analyzer/error/error.dartpackage:analyzer/src/generated/source.dartpackage:analyzer/src/generated/source_io.dartpackage:analyzer/src/generated/java_io.dartdart:io

Package not compatible with runtime native-aot

Because of the import of dart:mirrors via the import chain package:built_reducer/built_reducer.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/type_checker.dartdart:mirrors

Package not compatible with runtime web

Because of the import of dart:io via the import chain package:built_reducer/built_reducer.dartpackage:dart_style/dart_style.dartpackage:dart_style/src/exceptions.dartpackage:analyzer/error/error.dartpackage:analyzer/src/generated/source.dartpackage:analyzer/src/generated/source_io.dartpackage:analyzer/src/generated/java_io.dartdart:io

Maintenance suggestions

Maintain an example.

None of the files in the package's example/ directory matches known example patterns.

Common filename patterns include main.dart, example.dart, and built_reducer.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.6.0 <3.0.0
analyzer ^0.39.0 0.39.11
build >=0.12.6 <2.0.0 1.3.0
build_config >=0.2.6 <0.5.0 0.4.2
code_builder ^3.3.0 3.3.0
dart_style ^1.3.6 1.3.6
meta ^1.1.8 1.1.8
recase ^3.0.0 3.0.0
reducer ^0.6.0 0.6.0
source_gen ^0.9.0 0.9.5
Transitive dependencies
_fe_analyzer_shared 5.0.0
args 1.6.0
async 2.4.1
built_collection 4.3.2
built_value 7.1.0
charcode 1.1.3
checked_yaml 1.0.2
collection 1.14.13
convert 2.1.1
crypto 2.1.5
csslib 0.16.1
fixnum 0.10.11
glob 1.2.0
html 0.14.0+3
js 0.6.2
json_annotation 3.0.1
logging 0.11.4
matcher 0.12.8
node_interop 1.1.1
node_io 1.1.1
package_config 1.9.3
path 1.7.0
pub_semver 1.4.4
pubspec_parse 0.1.5
quiver 2.1.3
source_span 1.7.0
stack_trace 1.9.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.2.0
watcher 0.9.7+15
yaml 2.2.1
Dev dependencies
build_runner ^1.0.0
pedantic ^1.8.0 1.9.0 1.9.1
test ^1.6.0