built_redux 7.5.0

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 95

built_redux

Pub codecov.io


built_redux is a state management library written in dart that enforces immutability. built_redux is not only an implementation of redux, but also a framework for building middleware and reducers in a type safe manner.

Inspired by redux

Built using built_value

Framework bindings

flutter

Examples

Libraries

Documentation

7.5.0

  • allow 4.x.x of built_collection
  • added combineReducerBuilder to NestedReducerBuilder
  • added a NestedMiddlewareBuilder

7.4.5

  • open sdk range to dart 2!
  • update built_value and source_gen dependencies
  • use SharedPartBuilder rather than PartBuilder in the generator

7.4.4-dev

  • use typedef names in action generator

7.4.3-dev

  • update dependency range on analyzer
  • update dependency range on test
  • fix broken test caused by dart 2's new asyc behavior

7.4.2

  • add lint ignores to generated files

7.4.1-dev

  • open sourc-gen range
  • run tests on the dev compiler

7.4.1

  • fix cast issues around store changes in dart 2
  • open analyzer version range

7.4.0-dev

  • add build.yaml and build.dart to comply with build_runner 0.7.x

With the dev tag you can consume the latest versions of built_value, build, and build_runner that are only compatable with dart 2.

In order to migrate:

  • remove your old build scripts
  • update your pubspec to include
  build_runner: ^0.7.9
  • add a build.yaml to the root of your repo that contains the following:
targets:
  $default:
    builders:
      built_value_generator|built_value:
        enabled: false
  • run pub run build_runner build.

The build script is only a temporary measure until https://github.com/dart-lang/source_gen/issues/319 is resolved.

7.4.0

  • add built_redux_test_utils library - exposes an expectDispatched function for expecting a given action gets dispatched asynchronously
  • add combine to MiddlewareBuilder class - lets you combine middleware builders
  • add toString to Action class
  • add example
  • add docs

7.3.3

  • add changelog
  • update readme to include link to todoMVC repo

7.3.2

  • open dependency range on the build package

7.3.1

  • open dependency range on the built_collection package

7.3.0

  • dispose is now awaitable

7.2.0

  • Added actionStream stream to the store api so one can listen to changes resulting from a specific action name.
  • Fixed issues called out my adding implicit-dynamic and implicit-cast rules.

7.1.0

7.0.0

  • Breaking changes:
    • A breaking change in behavior was made to action dispatchers. Before action dispatchers executed the middleware/reducers asynchronously, but they now execute synchronously.

For example you may have:

int getCount(store) {
  print(store.state.count); // prints 0
  store.actions.increment(1);
  print(store.state.count); // would print 1 if actions were sync, 0 if async
  return store.state.count; // would return 1 if actions were sync, 0 if async
}

Before this function would return 0 because the state update that occurs from actions.increment would be processed in a future task. Now this function will return 1 because the state update that occurs from actions.increment is processed in the current task

6.0.0

Removes the BuiltReducer interface and the generated BuiltReducer implementation in favor of building a reducer function and passing it to the store at instantiation.

  • Breaking changes:
    • Store now takes a reducer
    • Nested reducers need to be built with the NestedReducerBuilder and merged wth the main ReducerBuilder using ReducerBuilder.addNestedReducer
    • Models no longer implement BuiltReducer
      • Remove references to the reducer on your models
    • Renamed ActionDispatcher.syncWithStore to setDispatcher
    • Renamed SubStateChange to SubstateChange

Reasoning:

  • Decouples your models and reducers.
  • Requires less generated code.
  • Reducing requires less map look ups. Previously N map look ups were required where N was the number of BuiltReducers in your state tree. Now only 1 map look up is required per action dispatched.

Examples:

  • Example model change. Remove the generated BuiltReducer mixin and the reducer getter

Before:

  abstract class Counter extends Object
     with CounterReducer
     implements Built<Counter, CounterBuilder> {
   int get count;

   get reducer => _reducer;

   Counter._();
   factory BaseCounter() => new _$BaseCounter._(count: 1);
 }

After:

  abstract class Counter implements Built<Counter, CounterBuilder> {
   int get count;

   Counter._();
   factory BaseCounter() => new _$BaseCounter._(count: 1);
 }
  • Example nested reducer change. Change NestedCounter's reducer builder to a NestedReducerBuilder. Pass the NestedReducerBuilder mapper functions from the main state/builder to the nested state/builder.

Before


// Built Reducer
abstract class BaseCounter extends Object
    with BaseCounterReducer
    implements Built<BaseCounter, BaseCounterBuilder> {
  int get count;

  BuiltList<int> get indexOutOfRangeList;

  NestedCounter get nestedCounter;

  @override
  get reducer => _baseReducer;

  // Built value constructor
  BaseCounter._();
  factory BaseCounter() => new _$BaseCounter._(
        count: 1,
        nestedCounter: new NestedCounter(),
      );
}

final _baseReducer = (new ReducerBuilder<BaseCounter, BaseCounterBuilder>()
      ..add(BaseCounterActionsNames.increment, _baseIncrement)
      ..add(BaseCounterActionsNames.decrement, _baseDecrement))
    .build();

abstract class NestedCounter extends Object
    with NestedCounterReducer
    implements Built<NestedCounter, NestedCounterBuilder> {
  int get count;

  get reducer => _nestedReducer;

  // Built value constructor
  NestedCounter._();
  factory NestedCounter() => new _$NestedCounter._(count: 1);
}

final _nestedReducer =  (new ReducerBuilder<NestedCounter, NestedCounterBuilder>()
          ..add(NestedCounterActionsNames.increment, _nestedIncrement)
          ..add(NestedCounterActionsNames.decrement, _nestedDecrement))
        .build();

After

abstract class BaseCounter implements Built<BaseCounter, BaseCounterBuilder> {
  int get count;

  NestedCounter get nestedCounter;

  BaseCounter._();
  factory BaseCounter() => new _$BaseCounter._(
        count: 1,
        nestedCounter: new NestedCounter(),
      );
}

// the reducer passed to the store
final reducer = (new ReducerBuilder<BaseCounter, BaseCounterBuilder>()
      ..add(BaseCounterActionsNames.increment, _baseIncrement)
      ..add(BaseCounterActionsNames.decrement, _baseDecrement)
      ..combineNested(_nestedReducer))
    .build();

abstract class NestedCounter implements Built<NestedCounter, NestedCounterBuilder> {
  int get count;

  // Built value constructor
  NestedCounter._();
  factory NestedCounter() => new _$NestedCounter._(count: 1);
}

final _nestedReducer = new NestedReducerBuilder<BaseCounter, BaseCounterBuilder,
    NestedCounter, NestedCounterBuilder>(
  (state) => state.nestedCounter,
  (builder) => builder.nestedCounter,
)
  ..add(NestedCounterActionsNames.increment, _nestedIncrement)
  ..add(NestedCounterActionsNames.decrement, _nestedDecrement);

example/example.dart

library example;

import 'package:built_value/built_value.dart';
import 'package:built_redux/built_redux.dart';

part 'example.g.dart';

void main() {
// Create a redux store holding the state of your app.
// Its API contains three getters: stream, state, and actions.
  final store = new Store<Counter, CounterBuilder, CounterActions>(
    reducerBuilder.build(), // build returns a reducer function
    new Counter(),
    new CounterActions(),
  );

  print(store.state.count); // 0
  store.actions.increment(1);
  print(store.state.count); // 1
  store.actions.increment(2);
  print(store.state.count); // 3
  store.actions.decrement(1);
  print(store.state.count); // 2
}

// This is a an implementation of ReduxActions. Actions are what middleware and ui
// components invoke a change to the redux store's state. By extending ReduxActions
// the built_redux generator will generate the required boilerplate to create
// each action and an ActionNames class. The ActionNames class is used to register
// reducers
abstract class CounterActions extends ReduxActions {
  ActionDispatcher<int> get increment;
  ActionDispatcher<int> get decrement;

  // factory to create on instance of the generated implementation of CounterActions
  CounterActions._();
  factory CounterActions() => new _$CounterActions();
}

// This is a built value. It is an immutable model that implements the Built interface.
// All of the state in your redux store is contained in a single built value model.
abstract class Counter implements Built<Counter, CounterBuilder> {
  /// [count] value of the counter
  int get count;

  // Built value constructor. The factory is returning the default state
  Counter._();
  factory Counter() => new _$Counter._(count: 0);
}

// These are reducer functions. They have a (state, action, builder) => void signature.
// They describes how an action transforms the state into the next state by applying changes to the builder supplied.
// You are required to use the builder passed, calling state.rebuild will NOT update the state in your redux store.
void increment(Counter state, Action<int> action, CounterBuilder builder) =>
    builder.count = state.count + action.payload;

void decrement(Counter state, Action<int> action, CounterBuilder builder) =>
    builder.count = state.count - action.payload;

// This is a reducer builder. Use of ReducerBuilder is not required, however it
// is strongly recommended as it gives you static type checking to make sure
// the payload for action name provided is the same as the expected payload
// for the action provided to your reducer. Calling .build() returns a reducer function
// that can be passed to the store's constructor.
final reducerBuilder = new ReducerBuilder<Counter, CounterBuilder>()
  ..add(CounterActionsNames.increment, increment)
  ..add(CounterActionsNames.decrement, decrement);

Use this package as a library

1. Depend on it

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


dependencies:
  built_redux: ^7.5.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or 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:built_redux/built_redux.dart';
  
Version Uploaded Documentation Archive
7.5.0 Sep 13, 2018 Go to the documentation of built_redux 7.5.0 Download built_redux 7.5.0 archive
7.4.5 Aug 2, 2018 Go to the documentation of built_redux 7.4.5 Download built_redux 7.4.5 archive
7.4.2 Jun 29, 2018 Go to the documentation of built_redux 7.4.2 Download built_redux 7.4.2 archive
7.4.1 Apr 17, 2018 Go to the documentation of built_redux 7.4.1 Download built_redux 7.4.1 archive
7.4.0 Feb 26, 2018 Go to the documentation of built_redux 7.4.0 Download built_redux 7.4.0 archive
7.3.5 Jan 31, 2018 Go to the documentation of built_redux 7.3.5 Download built_redux 7.3.5 archive
7.3.4 Jan 26, 2018 Go to the documentation of built_redux 7.3.4 Download built_redux 7.3.4 archive
7.3.3 Dec 31, 2017 Go to the documentation of built_redux 7.3.3 Download built_redux 7.3.3 archive
7.3.2 Dec 5, 2017 Go to the documentation of built_redux 7.3.2 Download built_redux 7.3.2 archive
7.3.1 Nov 30, 2017 Go to the documentation of built_redux 7.3.1 Download built_redux 7.3.1 archive

All 42 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
90
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]
95
Learn more about scoring.

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

  • Dart: 2.0.0
  • pana: 0.12.3

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:built_redux/built_redux.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev <3.0.0
analyzer ^0.32.1 0.32.5 0.33.0-alpha.0
build ^0.12.0 0.12.7+3
built_collection >=2.0.0 <5.0.0 4.0.0
built_value >=5.5.5 <7.0.0 6.1.3
source_gen ^0.9.0 0.9.1
test >=0.12.0 <2.0.0 1.3.3
Transitive dependencies
args 1.5.0
async 2.0.8
boolean_selector 1.0.4
charcode 1.1.2
collection 1.14.11
convert 2.0.2
crypto 2.0.6
csslib 0.14.5
dart_style 1.1.3
fixnum 0.10.8
front_end 0.1.4+1 0.1.5
glob 1.1.7
html 0.13.3+3
http 0.11.3+17
http_multi_server 2.0.5
http_parser 3.1.3
io 0.3.3
js 0.6.1+1
json_rpc_2 2.0.9
kernel 0.3.4+1 0.3.5
logging 0.11.3+2
matcher 0.12.3+1 0.12.4
meta 1.1.6
mime 0.9.6+2
multi_server_socket 1.0.2
node_preamble 1.4.4
package_config 1.0.5
package_resolver 1.0.4
path 1.6.2
plugin 0.2.0+3
pool 1.3.6
pub_semver 1.4.2
quiver 2.0.0+1
shelf 0.7.3+3
shelf_packages_handler 1.0.4
shelf_static 0.2.8
shelf_web_socket 0.2.2+4
source_map_stack_trace 1.1.5
source_maps 0.10.7
source_span 1.4.1
stack_trace 1.9.3
stream_channel 1.6.8
string_scanner 1.0.4
term_glyph 1.0.1
typed_data 1.1.6
utf 0.9.0+5
vm_service_client 0.2.6
watcher 0.9.7+10
web_socket_channel 1.0.9
yaml 2.1.15
Dev dependencies
build_runner ^0.10.0
build_test ^0.10.0
build_web_compilers ^0.4.0
built_value_generator ^6.0.0