Commit ce10ea12 authored by Brian Egan's avatar Brian Egan

A few small improvements

parent a9586e84
...@@ -2,7 +2,6 @@ library built_redux_sample; ...@@ -2,7 +2,6 @@ library built_redux_sample;
import 'package:built_redux/built_redux.dart'; import 'package:built_redux/built_redux.dart';
import 'package:built_redux_sample/containers/add_todo.dart'; import 'package:built_redux_sample/containers/add_todo.dart';
import 'package:built_redux_sample/data/todos_service.dart';
import 'package:built_redux_sample/models/models.dart'; import 'package:built_redux_sample/models/models.dart';
import 'package:built_redux_sample/localization.dart'; import 'package:built_redux_sample/localization.dart';
import 'package:built_redux_sample/actions/actions.dart'; import 'package:built_redux_sample/actions/actions.dart';
...@@ -18,24 +17,16 @@ void main() { ...@@ -18,24 +17,16 @@ void main() {
} }
class BuiltReduxApp extends StatelessWidget { class BuiltReduxApp extends StatelessWidget {
final TodosService service; final store = new Store<AppState, AppStateBuilder, AppActions>(
final Store<AppState, AppStateBuilder, AppActions> store; reducerBuilder.build(),
new AppState.loading(),
factory BuiltReduxApp() { new AppActions(),
final service = const TodosService(); middleware: [
final store = new Store<AppState, AppStateBuilder, AppActions>( createStoreTodosMiddleware(),
reducerBuilder.build(), ],
new AppState.loading(), );
new AppActions(),
middleware: [ BuiltReduxApp() {}
createStoreTodosMiddleware(service),
],
);
return new BuiltReduxApp._(store, service);
}
BuiltReduxApp._(this.store, this.service);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
......
...@@ -3,19 +3,21 @@ import 'package:built_redux_sample/data/todos_service.dart'; ...@@ -3,19 +3,21 @@ import 'package:built_redux_sample/data/todos_service.dart';
import 'package:built_redux_sample/models/models.dart'; import 'package:built_redux_sample/models/models.dart';
import 'package:built_redux_sample/actions/actions.dart'; import 'package:built_redux_sample/actions/actions.dart';
Middleware<AppState, AppStateBuilder, AppActions> createStoreTodosMiddleware( Middleware<AppState, AppStateBuilder, AppActions> createStoreTodosMiddleware([
TodosService service) => TodosService service = const TodosService(),
(new MiddlewareBuilder<AppState, AppStateBuilder, AppActions>() ]) {
..add(AppActionsNames.fetchTodosAction, createFetchTodos(service)) return (new MiddlewareBuilder<AppState, AppStateBuilder, AppActions>()
..add(AppActionsNames.addTodoAction, createSaveTodos<Todo>(service)) ..add(AppActionsNames.fetchTodosAction, createFetchTodos(service))
..add(AppActionsNames.clearCompletedAction, ..add(AppActionsNames.addTodoAction, createSaveTodos<Todo>(service))
createSaveTodos<Null>(service)) ..add(AppActionsNames.clearCompletedAction,
..add(AppActionsNames.deleteTodoAction, createSaveTodos<Null>(service))
createSaveTodos<String>(service)) ..add(
..add(AppActionsNames.toggleAllAction, createSaveTodos<Null>(service)) AppActionsNames.deleteTodoAction, createSaveTodos<String>(service))
..add(AppActionsNames.updateTodoAction, ..add(AppActionsNames.toggleAllAction, createSaveTodos<Null>(service))
createSaveTodos<UpdateTodoActionPayload>(service))) ..add(AppActionsNames.updateTodoAction,
.build(); createSaveTodos<UpdateTodoActionPayload>(service)))
.build();
}
MiddlewareHandler<AppState, AppStateBuilder, AppActions, Null> createFetchTodos( MiddlewareHandler<AppState, AppStateBuilder, AppActions, Null> createFetchTodos(
TodosService service) { TodosService service) {
......
...@@ -4,7 +4,6 @@ import 'package:flutter_redux/flutter_redux.dart'; ...@@ -4,7 +4,6 @@ import 'package:flutter_redux/flutter_redux.dart';
import 'package:redux/redux.dart'; import 'package:redux/redux.dart';
import 'package:redux_sample/actions/actions.dart'; import 'package:redux_sample/actions/actions.dart';
import 'package:redux_sample/containers/add_todo.dart'; import 'package:redux_sample/containers/add_todo.dart';
import 'package:redux_sample/data/todos_service.dart';
import 'package:redux_sample/localization.dart'; import 'package:redux_sample/localization.dart';
import 'package:redux_sample/models/models.dart'; import 'package:redux_sample/models/models.dart';
import 'package:redux_sample/reducers/app_state_reducer.dart'; import 'package:redux_sample/reducers/app_state_reducer.dart';
...@@ -16,21 +15,13 @@ void main() { ...@@ -16,21 +15,13 @@ void main() {
} }
class ReduxApp extends StatelessWidget { class ReduxApp extends StatelessWidget {
final service; final store = new Store<AppState>(
final store; appReducer,
initialState: new AppState.loading(),
middleware: createStoreTodosMiddleware(),
);
factory ReduxApp() { ReduxApp();
final service = const TodosService();
final store = new Store<AppState>(
appReducer,
initialState: new AppState.loading(),
middleware: createStoreTodosMiddleware(service),
);
return new ReduxApp._(store, service);
}
ReduxApp._(this.store, this.service);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
......
...@@ -5,7 +5,9 @@ import 'package:redux_sample/models/models.dart'; ...@@ -5,7 +5,9 @@ import 'package:redux_sample/models/models.dart';
import 'package:redux_sample/selectors/selectors.dart'; import 'package:redux_sample/selectors/selectors.dart';
import 'package:redux_sample/utils.dart'; import 'package:redux_sample/utils.dart';
List<Middleware<AppState>> createStoreTodosMiddleware(TodosService service) { List<Middleware<AppState>> createStoreTodosMiddleware([
TodosService service = const TodosService(),
]) {
final saveTodos = _createSaveTodos(service); final saveTodos = _createSaveTodos(service);
final loadTodos = _createLoadTodos(service); final loadTodos = _createLoadTodos(service);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment