import 'package:redux/redux.dart'; import '../models/yourLocation.dart'; import 'actions.dart'; final Reducer> yourLocationsReducer = combineReducers>(>>[ TypedReducer, AddedYourLocationAction>(_addedYourLocation), TypedReducer, DeletedYourLocationAction>( _deletedYourLocation), TypedReducer, UpdatedYourLocationAction>( _updatedYourLocation), TypedReducer, ToggledSubscriptionAction>( _toggledSubscriptionAction) ]); List _addedYourLocation( List yourLocations, AddedYourLocationAction action) { return List.from(yourLocations)..add(action.loc); } List _deletedYourLocation( List yourLocations, DeletedYourLocationAction action) { return yourLocations .where((YourLocation yourLocation) => yourLocation.id != action.id) .toList(); } List _updatedYourLocation( List yourLocations, UpdatedYourLocationAction action) { return yourLocations .map((YourLocation yourLocation) => yourLocation.id == action.loc.id ? action.loc : yourLocation) .toList(); } List _toggledSubscriptionAction( List yourLocations, ToggledSubscriptionAction action) { return yourLocations .map((YourLocation yourLocation) => yourLocation.id == action.loc.id ? action.loc : yourLocation) .toList(); }