Persistence
This commit is contained in:
parent
6bb107678e
commit
a6078af25a
|
|
@ -19,13 +19,17 @@ class FileStorage {
|
||||||
Future<dynamic> load() async {
|
Future<dynamic> load() async {
|
||||||
final file = await _getLocalFile();
|
final file = await _getLocalFile();
|
||||||
final contents = await file.readAsString();
|
final contents = await file.readAsString();
|
||||||
|
print('== LOAD ==');
|
||||||
|
print(contents);
|
||||||
return contents;
|
return contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<File> save(String data) async {
|
Future<File> save(String data) async {
|
||||||
final file = await _getLocalFile();
|
final file = await _getLocalFile();
|
||||||
|
|
||||||
|
print('== SAVE ==');
|
||||||
|
print(data);
|
||||||
|
|
||||||
return file.writeAsString(data);
|
return file.writeAsString(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import 'package:invoiceninja/data/repositories/persistence_repository.dart';
|
||||||
import 'package:invoiceninja/redux/app/app_state.dart';
|
import 'package:invoiceninja/redux/app/app_state.dart';
|
||||||
import 'package:invoiceninja/redux/auth/auth_actions.dart';
|
import 'package:invoiceninja/redux/auth/auth_actions.dart';
|
||||||
import 'package:invoiceninja/redux/dashboard/dashboard_actions.dart';
|
import 'package:invoiceninja/redux/dashboard/dashboard_actions.dart';
|
||||||
|
import 'package:invoiceninja/redux/product/product_actions.dart';
|
||||||
import 'package:invoiceninja/routes.dart';
|
import 'package:invoiceninja/routes.dart';
|
||||||
import 'package:redux/redux.dart';
|
import 'package:redux/redux.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
|
@ -21,9 +22,16 @@ List<Middleware<AppState>> createStorePersistenceMiddleware([
|
||||||
final deleteState = _createDeleteState(repository);
|
final deleteState = _createDeleteState(repository);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
TypedMiddleware<AppState, UserLogout>(deleteState),
|
||||||
TypedMiddleware<AppState, LoadStateRequest>(loadState),
|
TypedMiddleware<AppState, LoadStateRequest>(loadState),
|
||||||
TypedMiddleware<AppState, LoadDashboardSuccess>(dataLoaded),
|
TypedMiddleware<AppState, LoadDashboardSuccess>(dataLoaded),
|
||||||
TypedMiddleware<AppState, UserLogout>(deleteState),
|
|
||||||
|
TypedMiddleware<AppState, LoadProductsSuccess>(dataLoaded),
|
||||||
|
TypedMiddleware<AppState, AddProductSuccess>(dataLoaded),
|
||||||
|
TypedMiddleware<AppState, SaveProductSuccess>(dataLoaded),
|
||||||
|
TypedMiddleware<AppState, ArchiveProductSuccess>(dataLoaded),
|
||||||
|
TypedMiddleware<AppState, DeleteProductSuccess>(dataLoaded),
|
||||||
|
TypedMiddleware<AppState, RestoreProductSuccess>(dataLoaded),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -45,11 +53,12 @@ Middleware<AppState> _createLoadState(PersistenceRepository repository) {
|
||||||
Middleware<AppState> _createDataLoaded(PersistenceRepository repository) {
|
Middleware<AppState> _createDataLoaded(PersistenceRepository repository) {
|
||||||
return (Store<AppState> store, action, NextDispatcher next) {
|
return (Store<AppState> store, action, NextDispatcher next) {
|
||||||
|
|
||||||
|
// first process the action so the data is in the state
|
||||||
|
next(action);
|
||||||
|
|
||||||
if (store.state.isLoaded()) {
|
if (store.state.isLoaded()) {
|
||||||
repository.saveData(store.state);
|
repository.saveData(store.state);
|
||||||
}
|
}
|
||||||
|
|
||||||
next(action);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue