Commit ce10ea12 authored by Brian Egan's avatar Brian Egan

A few small improvements

parent a9586e84
......@@ -2,7 +2,6 @@ library built_redux_sample;
import 'package:built_redux/built_redux.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/localization.dart';
import 'package:built_redux_sample/actions/actions.dart';
......@@ -18,24 +17,16 @@ void main() {
}
class BuiltReduxApp extends StatelessWidget {
final TodosService service;
final Store<AppState, AppStateBuilder, AppActions> store;
factory BuiltReduxApp() {
final service = const TodosService();
final store = new Store<AppState, AppStateBuilder, AppActions>(
reducerBuilder.build(),
new AppState.loading(),
new AppActions(),
middleware: [
createStoreTodosMiddleware(service),
createStoreTodosMiddleware(),
],
);
return new BuiltReduxApp._(store, service);
}
BuiltReduxApp._(this.store, this.service);
BuiltReduxApp() {}
@override
Widget build(BuildContext context) {
......
......@@ -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/actions/actions.dart';
Middleware<AppState, AppStateBuilder, AppActions> createStoreTodosMiddleware(
TodosService service) =>
(new MiddlewareBuilder<AppState, AppStateBuilder, AppActions>()
Middleware<AppState, AppStateBuilder, AppActions> createStoreTodosMiddleware([
TodosService service = const TodosService(),
]) {
return (new MiddlewareBuilder<AppState, AppStateBuilder, AppActions>()
..add(AppActionsNames.fetchTodosAction, createFetchTodos(service))
..add(AppActionsNames.addTodoAction, createSaveTodos<Todo>(service))
..add(AppActionsNames.clearCompletedAction,
createSaveTodos<Null>(service))
..add(AppActionsNames.deleteTodoAction,
createSaveTodos<String>(service))
..add(
AppActionsNames.deleteTodoAction, createSaveTodos<String>(service))
..add(AppActionsNames.toggleAllAction, createSaveTodos<Null>(service))
..add(AppActionsNames.updateTodoAction,
createSaveTodos<UpdateTodoActionPayload>(service)))
.build();
}
MiddlewareHandler<AppState, AppStateBuilder, AppActions, Null> createFetchTodos(
TodosService service) {
......
......@@ -4,7 +4,6 @@ import 'package:flutter_redux/flutter_redux.dart';
import 'package:redux/redux.dart';
import 'package:redux_sample/actions/actions.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/models/models.dart';
import 'package:redux_sample/reducers/app_state_reducer.dart';
......@@ -16,21 +15,13 @@ void main() {
}
class ReduxApp extends StatelessWidget {
final service;
final store;
factory ReduxApp() {
final service = const TodosService();
final store = new Store<AppState>(
appReducer,
initialState: new AppState.loading(),
middleware: createStoreTodosMiddleware(service),
middleware: createStoreTodosMiddleware(),
);
return new ReduxApp._(store, service);
}
ReduxApp._(this.store, this.service);
ReduxApp();
@override
Widget build(BuildContext context) {
......
......@@ -5,7 +5,9 @@ import 'package:redux_sample/models/models.dart';
import 'package:redux_sample/selectors/selectors.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 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