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) {
// unsubscribe all locally to sync the subs state if (subscribedLocations is List) {
localLocations.forEach((location) => location.subscribed = false); // unsubscribe all locally to sync the subs state
// print('Local persisted: ${localLocations.length}'); localLocations.forEach((location) => location.subscribed = false);
subscribedLocations.forEach((subsLoc) { // print('Local persisted: ${localLocations.length}');
localLocations.firstWhere( subscribedLocations.forEach((subsLoc) {
(localLocation) => localLocation.id == subsLoc.id, orElse: () { localLocations
localLocations.add(subsLoc); .firstWhere(
}).subscribed = true; (localLocation) => localLocation.id == subsLoc.id, orElse: () {
}); localLocations.add(subsLoc);
})
.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;