Refactor SpacesRecursiveHelper to improve variable naming and enhance readability. Update mapping logic to clarify the distinction between updated and non-null spaces, ensuring better maintainability of the recursive space handling.

This commit is contained in:
Faris Armoush
2025-07-15 12:55:26 +03:00
parent df39fca050
commit 903c5dd29b

View File

@ -7,13 +7,15 @@ abstract final class SpacesRecursiveHelper {
SpaceDetailsModel updatedSpace,
) {
return spaces.map((space) {
if (space.uuid == updatedSpace.uuid) {
final isUpdatedSpace = space.uuid == updatedSpace.uuid;
if (isUpdatedSpace) {
return space.copyWith(
spaceName: updatedSpace.spaceName,
icon: updatedSpace.icon,
);
}
if (space.children.isNotEmpty) {
final hasChildren = space.children.isNotEmpty;
if (hasChildren) {
return space.copyWith(
children: recusrivelyUpdate(space.children, updatedSpace),
);
@ -26,7 +28,7 @@ abstract final class SpacesRecursiveHelper {
List<SpaceModel> spaces,
String spaceUuid,
) {
final s = spaces.map((space) {
final updatedSpaces = spaces.map((space) {
if (space.uuid == spaceUuid) return null;
if (space.children.isNotEmpty) {
return space.copyWith(
@ -35,7 +37,7 @@ abstract final class SpacesRecursiveHelper {
}
return space;
}).toList();
return s.whereType<SpaceModel>().toList();
final nonNullSpaces = updatedSpaces.whereType<SpaceModel>().toList();
return nonNullSpaces;
}
}