todos-contra-el-fuego-mobile/lib/redux/fireNotificationReducer.dart
vjrj 68ad4adbcf refactor: continue lint cleanup - 96 more issues fixed
- Add @immutable to classes with ==/hashCode (homePage, basicLocation, fireNotification, yourLocation, monitoredAreas)
- Fix camel_case_types (genericMap → GenericMap)
- Fix avoid_dynamic_calls (firesApi - typed responses)
- Fix use_build_context_synchronously (locationUtils)
- Fix always_put_control_body_on_new_line (4 reducers)
- Fix always_specify_types (placesAutocompleteUtils, reducers)
- Fix eol_at_end_of_file (4 files)
- Fix prefer_function_declarations_over_variables (introPage)
- Fix flutter_style_todos (fireMapReducer)

Build: APK generated, 0 errors, 0 warnings
2026-03-07 11:17:01 +01:00

52 lines
1.9 KiB
Dart

import 'package:redux/redux.dart';
import '../models/fireNotification.dart';
import 'actions.dart';
final Reducer<List<FireNotification>> fireNotificationReducer =
combineReducers<List<FireNotification>>(<Reducer<List<FireNotification>>>[
TypedReducer<List<FireNotification>, AddedFireNotificationAction>(
_addedFireNotification),
TypedReducer<List<FireNotification>, DeletedFireNotificationAction>(
_deletedFireNotification),
TypedReducer<List<FireNotification>, UpdatedFireNotificationAction>(
_updatedFireNotification),
TypedReducer<List<FireNotification>, DeletedAllFireNotificationAction>(
_deletedAllFireNotifications),
TypedReducer<List<FireNotification>, ReadedFireNotificationAction>(
_readedFireNotification)
]);
List<FireNotification> _addedFireNotification(
List<FireNotification> notifications, AddedFireNotificationAction action) {
return List<FireNotification>.from(notifications)..insert(0, action.notif);
}
List<FireNotification> _deletedFireNotification(
List<FireNotification> notifications,
DeletedFireNotificationAction action) {
return List<FireNotification>.from(notifications)..remove(action.notif);
}
List<FireNotification> _updatedFireNotification(
List<FireNotification> notifications,
UpdatedFireNotificationAction action) {
return notifications
.map((FireNotification notif) =>
notif.id == action.notif.id ? action.notif : notif)
.toList();
}
List<FireNotification> _readedFireNotification(
List<FireNotification> notifications, ReadedFireNotificationAction action) {
return notifications
.map((FireNotification yourLocation) =>
yourLocation.id == action.notif.id ? action.notif : yourLocation)
.toList();
}
List<FireNotification> _deletedAllFireNotifications(
List<FireNotification> notifications,
DeletedAllFireNotificationAction action) {
return <FireNotification>[];
}