From 903c5dd29b28b9143901f280fdc6c1610672e860 Mon Sep 17 00:00:00 2001 From: Faris Armoush Date: Tue, 15 Jul 2025 12:55:26 +0300 Subject: [PATCH] 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. --- .../main_module/helpers/spaces_recursive_helper.dart | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/pages/space_management_v2/main_module/helpers/spaces_recursive_helper.dart b/lib/pages/space_management_v2/main_module/helpers/spaces_recursive_helper.dart index e751e8d8..b725bf31 100644 --- a/lib/pages/space_management_v2/main_module/helpers/spaces_recursive_helper.dart +++ b/lib/pages/space_management_v2/main_module/helpers/spaces_recursive_helper.dart @@ -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 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().toList(); + final nonNullSpaces = updatedSpaces.whereType().toList(); + return nonNullSpaces; } }