Skip to content

Commit a2bbdac

Browse files
authored
Merge pull request #53 from brianegan/flutter-team-fixes
Version 4.0.0
2 parents cb629ce + 1162d0c commit a2bbdac

File tree

17 files changed

+134
-94
lines changed

17 files changed

+134
-94
lines changed

.travis.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ dart:
44
- stable
55
- dev
66
with_content_shell: false
7-
dart_task:
8-
- test: --platform vm
9-
- dartanalyzer: --fatal-warnings lib
7+
script:
8+
- dartanalyzer --fatal-infos --fatal-warnings ./
9+
- dartfmt -n ./lib --set-exit-if-changed
10+
- pub global activate coverage
11+
- pub run test test/redux_test.dart
12+
- dart --disable-service-auth-codes --enable-vm-service=8111 --pause-isolates-on-exit test/redux_test.dart &
13+
- nohup pub global run coverage:collect_coverage --port=8111 --out=coverage.json --wait-paused --resume-isolates
14+
- pub global run coverage:format_coverage --lcov --in=coverage.json --out=lcov.info --packages=.packages --report-on=lib
15+
after_success:
16+
- bash <(curl -s https://codecov.io/bash)

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
# 4.0.0
2+
3+
* `dispatch` returns the provided action
4+
* Removed Dart 1.x support
5+
* Enforce Pedantic package lint rules
6+
* Enforce `public_member_api_docs` lint rule and add docs to missing parts
7+
* Update `travis.yml` with support for dartfmt, analysis, and code coverage
8+
* Add coverage badge to root README
9+
* Pub.dev updates
10+
* Longer description
11+
* https for package url
12+
* update example folder to include README
13+
114
# 3.0.1
215

316
* Update README based on feedback

README.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
# redux.dart
22

33
[![Build Status](https://api.travis-ci.org/johnpryan/redux.dart.svg?branch=master)](https://travis-ci.org/johnpryan/redux.dart)
4+
[![codecov](https://codecov.io/gh/johnpryan/redux.dart/branch/master/graph/badge.svg)](https://codecov.io/gh/johnpryan/redux.dart)
45

56
[Redux](http://redux.js.org/) for Dart using generics for typed State. It includes a rich ecosystem of [Docs](#docs), [Middleware](#middleware), [Dev Tools](#dev-tools) and can be combined with Flutter using the [flutter_redux](https://pub.dartlang.org/packages/flutter_redux) package.
67

7-
## Redux 3.0.0 Migration & Dart 2 support
8-
9-
In order to support Dart 2, some of the APIs needed to change. The good news: This actually simplifies Redux! The bad news: you may need to update your projects.
10-
11-
* Change `ReducerBinding` to `TypedReducer`
12-
* Remove `combineTypedReducer`. Use `combineReducers` with a combination of normal reducers and/or `TypedReducer`s.
13-
* Change `MiddlewareBinding` to `TypedMiddleware`.
14-
* Remove `combineTypedMiddleware` -- no longer needed! Just create a normal `List<Middleware<State>>`!
15-
168
## Docs
179

1810
* [Motivation and Principles](https://github.com/johnpryan/redux.dart/blob/master/doc/why.md) - Learn why Redux might make sense for your app and the principles behind it.

analysis_options.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
include: package:pedantic/analysis_options.yaml
2+
13
analyzer:
24
strong-mode:
35
implicit-casts: false
@@ -12,3 +14,4 @@ linter:
1214
- test_types_in_equals
1315
- unrelated_type_equality_checks
1416
- valid_regexps
17+
- public_member_api_docs

example/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Examples
2+
3+
* [Counter example](https://github.com/johnpryan/redux.dart/tree/master/example/vanilla_counter) - an example of how to search as a user types, demonstrating both the Middleware and Epic approaches.
4+
* [Middleware example](https://github.com/johnpryan/redux.dart/tree/master/example/middleware) - an example of how to search as a user types, demonstrating both the Middleware and Epic approaches.
5+
* [Combining Reducers example](https://github.com/johnpryan/redux.dart/tree/master/example/combined_reducers) - a port of the standard "Counter Button" example from Flutter

example/combined_reducers/index.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ enum AppAction { increment, decrement }
2828
// to a console. For that, use Middleware.
2929
AppState counterReducer(AppState state, dynamic action) {
3030
if (action == AppAction.increment) {
31-
return new AppState(state.count + 1, state.clickCount);
31+
return AppState(state.count + 1, state.clickCount);
3232
}
3333
if (action == AppAction.decrement) {
34-
return new AppState(state.count - 1, state.clickCount);
34+
return AppState(state.count - 1, state.clickCount);
3535
}
3636

3737
return state;
@@ -41,10 +41,10 @@ AppState counterReducer(AppState state, dynamic action) {
4141
// can be used for Action and State.
4242
AppState clickCounterReducer(AppState state, dynamic action) {
4343
if (action == AppAction.increment) {
44-
return new AppState(state.count, state.clickCount + 1);
44+
return AppState(state.count, state.clickCount + 1);
4545
}
4646
if (action == AppAction.decrement) {
47-
return new AppState(state.count, state.clickCount + 1);
47+
return AppState(state.count, state.clickCount + 1);
4848
}
4949

5050
return state;
@@ -56,9 +56,9 @@ void main() {
5656
counterReducer,
5757
clickCounterReducer,
5858
]);
59-
final store = new Store<AppState>(
59+
final store = Store<AppState>(
6060
combined,
61-
initialState: new AppState(0, 0),
61+
initialState: AppState(0, 0),
6262
);
6363

6464
render(store.state);
@@ -79,7 +79,7 @@ void main() {
7979
});
8080

8181
querySelector('#incrementAsync').onClick.listen((_) {
82-
new Future<Null>.delayed(new Duration(milliseconds: 1000)).then((_) {
82+
Future<Null>.delayed(Duration(milliseconds: 1000)).then((_) {
8383
store.dispatch(AppAction.increment);
8484
});
8585
});

example/index.html

Lines changed: 0 additions & 15 deletions
This file was deleted.

example/middleware/index.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ int counterReducer(int state, dynamic action) {
3131
// A piece of middleware that will log all actions with a timestamp to your
3232
// console!
3333
void loggingMiddleware(Store<int> store, dynamic action, NextDispatcher next) {
34-
print('${new DateTime.now()}: $action');
34+
print('${DateTime.now()}: $action');
3535

3636
next(action);
3737
}
3838

3939
void main() {
4040
// Create a new reducer and store for the app.
41-
final store = new Store<int>(
41+
final store = Store<int>(
4242
counterReducer,
4343
initialState: 0,
4444
middleware: <Middleware<int>>[loggingMiddleware],
@@ -62,7 +62,7 @@ void main() {
6262
});
6363

6464
querySelector('#incrementAsync').onClick.listen((_) {
65-
new Future<Null>.delayed(new Duration(milliseconds: 1000)).then((_) {
65+
Future<Null>.delayed(Duration(milliseconds: 1000)).then((_) {
6666
store.dispatch(Actions.increment);
6767
});
6868
});

example/vanilla_counter/index.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ int counterReducer(int state, dynamic action) {
3030

3131
void main() {
3232
// Create a new reducer and store for the app.
33-
final store = new Store(counterReducer, initialState: 0);
33+
final store = Store(counterReducer, initialState: 0);
3434

3535
render(store.state);
3636
store.onChange.listen(render);
@@ -50,7 +50,7 @@ void main() {
5050
});
5151

5252
querySelector('#incrementAsync').onClick.listen((_) {
53-
new Future<Null>.delayed(new Duration(milliseconds: 1000)).then((_) {
53+
Future<Null>.delayed(Duration(milliseconds: 1000)).then((_) {
5454
store.dispatch(Actions.increment);
5555
});
5656
});

lib/src/store.dart

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ typedef State Reducer<State>(State state, dynamic action);
4545
///
4646
/// final store = new Store<int>(new CounterReducer());
4747
abstract class ReducerClass<State> {
48+
/// The [Reducer] function that converts the current state and action into a
49+
/// new state
4850
State call(State state, dynamic action);
4951
}
5052

@@ -98,6 +100,7 @@ typedef void Middleware<State>(
98100
/// middleware: [new LoggingMiddleware()],
99101
/// );
100102
abstract class MiddlewareClass<State> {
103+
/// A [Middleware] function that intercepts a dispatched action
101104
void call(Store<State> store, dynamic action, NextDispatcher next);
102105
}
103106

@@ -159,21 +162,35 @@ class Store<State> {
159162
State _state;
160163
List<NextDispatcher> _dispatchers;
161164

165+
/// Creates an instance of a Redux Store.
166+
///
167+
/// The [reducer] argument specifies how the state should be changed in
168+
/// response to dispatched actions.
169+
///
170+
/// The optional [initialState] argument defines the State of the store when
171+
/// the Store is first created.
172+
///
173+
/// The optional [middleware] argument takes a list of [Middleware] functions
174+
/// or [MiddlewareClass]. See the [Middleware] documentation for information
175+
/// on how they are used.
176+
///
177+
/// The [syncStream] argument allows you to use a synchronous
178+
/// [StreamController] instead of an async `StreamController` under the hood.
179+
/// By default, the Stream is async.
162180
Store(
163181
this.reducer, {
164182
State initialState,
165183
List<Middleware<State>> middleware = const [],
166-
bool syncStream: false,
184+
bool syncStream = false,
167185

168186
/// If set to true, the Store will not emit onChange events if the new State
169187
/// that is returned from your [reducer] in response to an Action is equal
170188
/// to the previous state.
171189
///
172190
/// Under the hood, it will use the `==` method from your State class to
173191
/// determine whether or not the two States are equal.
174-
bool distinct: false,
175-
})
176-
: _changeController = new StreamController.broadcast(sync: syncStream) {
192+
bool distinct = false,
193+
}) : _changeController = StreamController.broadcast(sync: syncStream) {
177194
_state = initialState;
178195
_dispatchers = _createDispatchers(
179196
middleware,
@@ -246,8 +263,9 @@ class Store<State> {
246263
/// to the state using the given [Reducer]. Please note: [Middleware] can
247264
/// intercept actions, and can modify actions or stop them from passing
248265
/// through to the reducer.
249-
void dispatch(dynamic action) {
266+
dynamic dispatch(dynamic action) {
250267
_dispatchers[0](action);
268+
return action;
251269
}
252270

253271
/// Closes down the Store so it will no longer be operational. Only use this

0 commit comments

Comments
 (0)