reducer 0.5.0 copy "reducer: ^0.5.0" to clipboard
reducer: ^0.5.0 copied to clipboard

outdated

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

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';

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

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

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

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

From there, to run the code generator, you have two possibilities:

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

Resulting file #

You have a result in the example folder.

1
likes
0
pub points
0%
popularity

Publisher

unverified uploader

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

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

meta

More

Packages that depend on reducer