Skip to content

Commit 024da0e

Browse files
authored
Merge pull request #14 from davidmarne/2.0.0
2.0.0
2 parents 2c18790 + fb8d554 commit 024da0e

File tree

8 files changed

+31
-27
lines changed

8 files changed

+31
-27
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
language: dart
22
dart:
3-
- 1.22.1
3+
- 1.24.2
44
script:
5+
- dart tool/build.dart
56
- pub run dart_dev format --check
67
- pub run dart_dev analyze
7-
- dart tool/build.dart
88
- pub run dart_dev test
99
- pub run dart_dev coverage --no-html
1010
- bash <(curl -s https://codecov.io/bash) -f coverage/coverage.lcov

analysis_options.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
analyzer:
2+
strong-mode: true

lib/src/middleware.dart

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,24 @@ class MiddlewareApi<State extends BuiltReducer<State, StateBuilder>,
2525
/// Action<T>, and a builder of type StateBuilder
2626
class MiddlewareBuilder<State extends BuiltReducer<State, StateBuilder>,
2727
StateBuilder extends Builder<State, StateBuilder>, Actions extends ReduxActions> {
28-
var _map = new Map<String, MiddlewareHandler<State, StateBuilder, Actions>>();
28+
var _map = new Map<String, MiddlewareHandler<State, StateBuilder, Actions, dynamic>>();
2929

30-
void add<T>(ActionName<T> aMgr, MiddlewareHandler<State, StateBuilder, Actions> handler) {
30+
void add<T>(ActionName<T> aMgr, MiddlewareHandler<State, StateBuilder, Actions, T> handler) {
3131
_map[aMgr.name] = handler;
3232
}
3333

3434
/// build returns a [Middleware] function that handles all actions added with [add]
3535
Middleware<State, StateBuilder, Actions> build() =>
36-
(MiddlewareApi<State, StateBuilder, Actions> api) => (ActionHandler next) => (Action action) {
37-
var handler = _map[action.name];
38-
if (handler != null) {
39-
handler(api, next, action);
40-
return;
41-
}
42-
43-
next(action);
44-
};
36+
(MiddlewareApi<State, StateBuilder, Actions> api) =>
37+
(ActionHandler next) => (Action<dynamic> action) {
38+
var handler = _map[action.name];
39+
if (handler != null) {
40+
handler(api, next, action);
41+
return;
42+
}
43+
44+
next(action);
45+
};
4546
}
4647

4748
/// [MiddlewareHandler] is a function that handles an action in a middleware. Its is only for
@@ -50,4 +51,5 @@ class MiddlewareBuilder<State extends BuiltReducer<State, StateBuilder>,
5051
typedef void MiddlewareHandler<
5152
State extends BuiltReducer<State, StateBuilder>,
5253
StateBuilder extends Builder<State, StateBuilder>,
53-
Actions extends ReduxActions>(MiddlewareApi<State, StateBuilder, Actions> api, ActionHandler next, Action action);
54+
Actions extends ReduxActions,
55+
Payload>(MiddlewareApi<State, StateBuilder, Actions> api, ActionHandler next, Action<Payload> action);

lib/src/store.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import 'store_change.dart';
1414
class Store<State extends BuiltReducer<State, StateBuilder>,
1515
StateBuilder extends Builder<State, StateBuilder>, Actions extends ReduxActions> {
1616
// stream used for dispatching actions
17-
final StreamController<Action<dynamic>> _dispatch = new StreamController.broadcast();
17+
final StreamController<Action<dynamic>> _dispatch = new StreamController();
1818

1919
// stream used to dispatch changes to the state
2020
final StreamController<StoreChange<State, StateBuilder, dynamic>> _stateController =
@@ -44,7 +44,7 @@ class Store<State extends BuiltReducer<State, StateBuilder>,
4444
if (_state == state) return;
4545

4646
// update the internal state and publish the change
47-
_stateController.add(new StoreChange<State, StateBuilder, dynamic>(state, _state, action));
47+
_stateController.add(new StoreChange<State, StateBuilder, Actions>(state, _state, action));
4848
_state = state;
4949
};
5050

pubspec.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: built_redux
2-
version: 1.0.0
2+
version: 2.0.0
33
description:
44
A state management library written in dart that enforces immutability
55
authors:
@@ -14,10 +14,9 @@ dependencies:
1414
dev_dependencies:
1515
build_runner: ^0.3.0
1616
built_value_generator: ^1.0.0
17-
coverage: "^0.7.3"
1817
dart_dev: "^1.0.0"
19-
dart_style: ">=0.2.0 <0.3.0"
20-
dartdoc: ">=0.8.0 <=0.10.0"
18+
dart_style: '>=0.2.4 <2.0.0'
19+
coverage: ^0.7.3
2120
test: "^0.12.0"
2221

2322
environment:

test/unit/redux_test.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ main() {
3333
setup();
3434
Completer onStateChangeCompleter =
3535
new Completer<StoreChange<BaseCounter, BaseCounterBuilder, BaseCounterActions>>();
36-
store.stream.listen(
37-
(StoreChange<BaseCounter, BaseCounterBuilder, BaseCounterActions> state) =>
38-
onStateChangeCompleter.complete(state));
36+
store.stream.listen((StoreChange<BaseCounter, BaseCounterBuilder, dynamic> state) =>
37+
onStateChangeCompleter.complete(state));
3938
store.actions.increment(4);
4039
var stateChange = await onStateChangeCompleter.future;
4140
expect(stateChange.prev.count, 1);

test/unit/test_counter.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,10 @@ abstract class MiddlewareActions extends ReduxActions {
9191
factory MiddlewareActions() => new _$MiddlewareActions();
9292
}
9393

94-
var counterMiddleware = (new MiddlewareBuilder<BaseCounter, BaseCounterBuilder, BaseCounterActions>()
95-
..add<int>(MiddlewareActionsNames.increment, _doubleIt))
96-
.build();
94+
var counterMiddleware =
95+
(new MiddlewareBuilder<BaseCounter, BaseCounterBuilder, BaseCounterActions>()
96+
..add<int>(MiddlewareActionsNames.increment, _doubleIt))
97+
.build();
9798

9899
_doubleIt(MiddlewareApi<BaseCounter, BaseCounterBuilder, BaseCounterActions> api,
99100
ActionHandler next, Action<int> action) {

tool/dev.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import 'package:dart_dev/dart_dev.dart' show dev, config;
55
main(List<String> args) async {
66
const directories = const <String>[
77
'lib/',
8-
'test/',
8+
'lib/src/',
9+
'test/unit/',
910
];
1011

1112
config.format..lineLength = 100;

0 commit comments

Comments
 (0)