Process yourLocations even without response

This commit is contained in:
Vicente J. Ruiz Jurado 2018-08-03 08:47:37 +02:00
parent 8025d9c3d5
commit add46379bd

View file

@ -142,16 +142,19 @@ void fetchDataMiddleware(Store<AppState> store, action, NextDispatcher next) {
// Our reducer will then update the State using these YourLocations. // Our reducer will then update the State using these YourLocations.
// print('Subscribed to: ${subscribedLocations.length}'); // print('Subscribed to: ${subscribedLocations.length}');
loadYourLocations().then((localLocations) { loadYourLocations().then((localLocations) {
if (subscribedLocations is List) {
// unsubscribe all locally to sync the subs state // unsubscribe all locally to sync the subs state
localLocations.forEach((location) => location.subscribed = false); localLocations.forEach((location) => location.subscribed = false);
// print('Local persisted: ${localLocations.length}'); // print('Local persisted: ${localLocations.length}');
subscribedLocations.forEach((subsLoc) { subscribedLocations.forEach((subsLoc) {
localLocations.firstWhere( localLocations
.firstWhere(
(localLocation) => localLocation.id == subsLoc.id, orElse: () { (localLocation) => localLocation.id == subsLoc.id, orElse: () {
localLocations.add(subsLoc); localLocations.add(subsLoc);
}).subscribed = true; })
.subscribed = true;
}); });
}
localLocations.forEach((yl) { localLocations.forEach((yl) {
api.getYourLocationFireStats(store.state, yl).then((value) { api.getYourLocationFireStats(store.state, yl).then((value) {
yl.currentNumFires = value.numFires; yl.currentNumFires = value.numFires;