Skip to content

Commit eb2bc1e

Browse files
authored
Merge pull request #86 from davidmarne/dart-2-dev
Dart 7.4.5 - Dart 2
2 parents 06f6556 + b9b0934 commit eb2bc1e

20 files changed

+512
-439
lines changed

Diff for: .travis.yml

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
language: dart
2-
dart:
3-
- stable
2+
dart: dev
3+
sudo: required
4+
addons:
5+
chrome: stable
6+
before_install:
7+
- export DISPLAY=:99.0
8+
- sh -e /etc/init.d/xvfb start
9+
- "t=0; until (xdpyinfo -display :99 &> /dev/null || test $t -gt 10); do sleep 1; let t=$t+1; done"
10+
411
script:
5-
- dart tool/build.dart
6-
- pub run dart_dev format --check
7-
- pub run dart_dev analyze
8-
- pub run dart_dev test -p vm
9-
- pub run dart_dev coverage --no-html
10-
- bash <(curl -s https://codecov.io/bash) -f coverage/coverage.lcov
12+
- pub run build_runner build --delete-conflicting-outputs
13+
- dartfmt -n --set-exit-if-changed lib/
14+
- dartanalyzer --fatal-warnings --fatal-infos lib/
15+
- pub run build_runner test --delete-conflicting-outputs
16+
- pub run build_runner test --delete-conflicting-outputs -- -p chrome

Diff for: CHANGELOG.md

+51
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,63 @@
1+
## 7.4.5
2+
3+
* open sdk range to dart 2!
4+
* update built_value and source_gen dependencies
5+
* use SharedPartBuilder rather than PartBuilder in the generator
6+
7+
## 7.4.4-dev
8+
9+
* use typedef names in action generator
10+
11+
## 7.4.3-dev
12+
13+
* update dependency range on analyzer
14+
* update dependency range on test
15+
* fix broken test caused by dart 2's new asyc behavior
16+
117
## 7.4.2
218

319
* add lint ignores to generated files
420

21+
## 7.4.1-dev
22+
23+
* open sourc-gen range
24+
* run tests on the dev compiler
25+
526
## 7.4.1
627

728
* fix cast issues around store changes in dart 2
829
* open analyzer version range
930

31+
## 7.4.0-dev
32+
33+
* add build.yaml and build.dart to comply with build_runner 0.7.x
34+
35+
With the dev tag you can consume the latest versions of built_value, build, and build_runner that are only compatable with dart 2.
36+
37+
In order to migrate:
38+
39+
* remove your old build scripts
40+
* update your pubspec to include
41+
42+
```yaml
43+
build_runner: ^0.7.9
44+
```
45+
46+
* add a build.yaml to the root of your repo that contains the following:
47+
48+
```yaml
49+
targets:
50+
$default:
51+
builders:
52+
built_value_generator|built_value:
53+
enabled: false
54+
```
55+
56+
* run `pub run build_runner build`.
57+
58+
The build script is only a temporary measure until https://github.com/dart-lang/source_gen/issues/319 is resolved.
59+
60+
1061
## 7.4.0
1162

1263
* add built_redux_test_utils library - exposes an expectDispatched function for expecting a given action gets dispatched asynchronously

Diff for: README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
[![Pub](https://img.shields.io/pub/v/built_redux.svg)](https://pub.dartlang.org/packages/built_redux)
44
[![codecov.io](http://codecov.io/github/davidmarne/built_redux/coverage.svg?branch=master)](http://codecov.io/github/davidmarne/built_redux?branch=master)
55

6+
----
7+
68
built_redux is a state management library written in dart that enforces immutability.
79
built_redux is not only an implementation of [redux][redux_git], but also a framework for building middleware and reducers in a type safe manner.
810

911
Inspired by [redux][redux_git]
1012

1113
Built using [built_value][built_value_git]
1214

13-
## Using dart 2?
14-
Check out the [dart 2 dev branch](https://github.com/davidmarne/built_redux/tree/dart-2-dev), which works with the latest versions of build, build_runner, and built_value.
15-
1615
## Framework bindings
1716

1817
[flutter]

Diff for: build.yaml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
targets:
2+
$default:
3+
builders:
4+
built_redux|built_redux:
5+
enabled: true
6+
7+
builders:
8+
built_redux:
9+
target: ":built_redux"
10+
import: "package:built_redux/builder.dart"
11+
builder_factories: ["builtRedux"]
12+
build_extensions: {".dart": [".built_redux.g.part"]}
13+
auto_apply: dependents
14+
build_to: cache
15+
applies_builders: ["source_gen|combining_builder"]

Diff for: doc/basics/setup.md

+7-31
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,16 @@
11
# Setup
22

3-
built_value and built_redux both rely on code generation.
3+
built_value and built_redux both rely on build_runner for code generation.
44

55
1. Add the `built_redux` package as a dependency in your `pubspec.yaml`.
6+
67
```yaml
78
dependencies:
8-
built_redux: ^7.0.0
9-
built_value: ^5.0.0
9+
built_redux: ^7.4.5
10+
built_value: '>=5.5.5 <7.0.0'
1011
dev_dependencies:
11-
build_runner: ^0.6.0
12-
built_value_generator: '>=4.1.0 < 6.0.0'
13-
source_gen: ^0.7.0
12+
build_runner: ^0.9.0
13+
built_value_generator: ^6.0.0
1414
```
1515
16-
2. Create a script to run generators for generating built_values and built_redux action classes.
17-
```dart
18-
import 'dart:async';
19-
20-
import 'package:build_runner/build_runner.dart';
21-
import 'package:built_value_generator/built_value_generator.dart';
22-
import 'package:source_gen/source_gen.dart';
23-
import 'package:built_redux/generator.dart';
24-
25-
Future main(List<String> args) async {
26-
await build([
27-
new BuildAction(
28-
new PartBuilder([
29-
new BuiltValueGenerator(),
30-
new BuiltReduxGenerator(),
31-
]),
32-
// your lib name here
33-
'built_redux',
34-
// tweak the files that invoke the generator here
35-
inputs: const ['lib/**/*.dart'])
36-
], deleteFilesByDefault: true);
37-
}
38-
```
39-
40-
3. Run the build script from the command line to generate your built_values and built_redux action classes by running `dart [build script name].dart`
16+
2. Use build runner to build the generated files by executing `pub run build_runner build`

Diff for: example/example.g.dart

+33-31
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: lib/builder.dart

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import 'package:build/build.dart';
2+
import 'package:source_gen/source_gen.dart';
3+
4+
import 'generator.dart';
5+
6+
Builder builtRedux(BuilderOptions _) => new SharedPartBuilder([
7+
new BuiltReduxGenerator(),
8+
], 'built_redux');

Diff for: lib/generator.dart

+26-13
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ String _allActionDispatcherFieldsTemplate(ClassElement element) =>
6464
element, _reduxActionFieldTemplate, _needsReduxActions);
6565

6666
String _actionDispatcherFieldTemplate(ClassElement e, FieldElement f) {
67-
final genericType = _getActionGenericType(f);
67+
final genericType =
68+
_getActionGenericType((f.type as InterfaceType).typeArguments.first);
6869
return 'final ActionDispatcher<${genericType}> ${f.name} = new ActionDispatcher<${genericType}>(\'${e.name}-${f.name}\');';
6970
}
7071

@@ -99,7 +100,8 @@ String _allActionNamesFieldsTemplate(ClassElement element) =>
99100
element, _actionNameTemplate, _isActionDispatcher);
100101

101102
String _actionNameTemplate(ClassElement e, FieldElement f) {
102-
final genericType = _getActionGenericType(f);
103+
final genericType =
104+
_getActionGenericType((f.type as InterfaceType).typeArguments.first);
103105
return 'static final ActionName<${genericType}> ${f.name} = new ActionName<${genericType}>(\'${e.name}-${f.name}\');';
104106
}
105107

@@ -147,25 +149,36 @@ bool _hasSuperType(ClassElement classElement, String type) =>
147149
.any((interfaceType) => interfaceType.name == type) &&
148150
!classElement.displayName.startsWith('_\$');
149151

150-
String _getActionGenericType(FieldElement e) {
151-
var typeArgument =
152-
(e.type as InterfaceType).typeArguments.first as ParameterizedType;
153-
// generic type has generic type parameters?
154-
if (typeArgument.typeArguments.isEmpty ||
155-
typeArgument.typeArguments.every((ta) => ta.name == 'dynamic')) {
156-
return typeArgument.name;
152+
String _getActionGenericType(DartType type) {
153+
if (type is FunctionType) {
154+
final generics =
155+
_correctUnresolvedGenerics(type.typeArguments, type.typeParameters);
156+
if (generics.isEmpty) return typeNameOf(type);
157+
return typeNameOf(type) + '<${generics.join(',')}>';
157158
}
158159

159-
final typeArguments =
160-
typeArgument.typeArguments.map((ta) => ta.toString()).toList();
160+
if (type is ParameterizedType) {
161+
final generics =
162+
_correctUnresolvedGenerics(type.typeArguments, type.typeParameters);
163+
if (generics.isEmpty) return type.name;
164+
return type.name + '<${generics.join(',')}>';
165+
}
166+
167+
if (type.isVoid) return 'void';
168+
169+
return 'dynamic';
170+
}
161171

172+
List<String> _correctUnresolvedGenerics(
173+
List<DartType> args, List<TypeParameterElement> params) {
162174
// hack for thunks/repatches or any other type argument list where
163175
// any given argument is a Built and the proceding is a Builder
164176
// and the builder is dynamic in the typeArguments list becauses it is
165177
// yet to be generated. This is complex and a bit awkward but
166178
// it is written this way to be very careful not to make any unintended
167179
// changes the the typeArguments list.
168-
final boundParams = typeArgument.typeParameters.map((e) => e.bound);
180+
final typeArguments = args.map((ta) => ta.toString()).toList();
181+
final boundParams = params.map((e) => e.bound);
169182
for (int i = 0; i < boundParams.length; i++) {
170183
// get the bound param at this spot
171184
final b = boundParams.elementAt(i);
@@ -192,5 +205,5 @@ String _getActionGenericType(FieldElement e) {
192205
}
193206
}
194207

195-
return '${typeArgument.name}<${typeArguments.join(',')}>';
208+
return typeArguments;
196209
}

Diff for: lib/src/store.dart

+4-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ class Store<
4343
if (_state == state) return;
4444

4545
// update the internal state and publish the change
46-
_stateController.add(
47-
new StoreChange<State, StateBuilder, dynamic>(state, _state, action));
46+
if (!_stateController.isClosed)
47+
_stateController.add(new StoreChange<State, StateBuilder, dynamic>(
48+
state, _state, action));
49+
4850
_state = state;
4951
};
5052

Diff for: pubspec.yaml

+12-17
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
11
name: built_redux
2-
version: 7.4.2
2+
version: 7.4.5
33
description:
44
A state management library written in dart that enforces immutability
55
authors:
66
- David Marne <[email protected]>
77
homepage: https://github.com/davidmarne/built_redux
88
dependencies:
9-
analyzer: '>=0.29.0 <0.32.0'
10-
build: '>=0.10.0 <0.12.0'
11-
built_collection: '>=1.0.0 <4.0.0'
12-
built_value: '>=4.1.0 < 6.0.0'
13-
source_gen: ^0.7.0
14-
test: ^0.12.0
9+
analyzer: ^0.32.1
10+
build: ^0.12.0
11+
built_collection: '>=2.0.0 <4.0.0'
12+
built_value: '>=5.5.5 <7.0.0'
13+
source_gen: ^0.9.0
14+
test: '>=0.12.0 <2.0.0'
1515

1616
dev_dependencies:
17-
build_runner: ^0.6.0
18-
built_value_generator: ^5.0.0
19-
dart_dev: ^1.9.2
20-
dart_style: ^1.0.0
21-
coverage: ^0.9.3
17+
build_runner: ^0.10.0
18+
build_test: ^0.10.0
19+
built_value_generator: ^6.0.0
20+
build_web_compilers: ^0.4.0
2221

2322
environment:
24-
sdk: ">=1.17.1 <2.0.0"
25-
26-
transformers:
27-
- test/pub_serve:
28-
$include: test/**_test{.*,}.dart
23+
sdk: '>=2.0.0-dev <3.0.0'

0 commit comments

Comments
 (0)