mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-08-25 21:09:41 +00:00
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:
@ -7,13 +7,15 @@ abstract final class SpacesRecursiveHelper {
|
|||||||
SpaceDetailsModel updatedSpace,
|
SpaceDetailsModel updatedSpace,
|
||||||
) {
|
) {
|
||||||
return spaces.map((space) {
|
return spaces.map((space) {
|
||||||
if (space.uuid == updatedSpace.uuid) {
|
final isUpdatedSpace = space.uuid == updatedSpace.uuid;
|
||||||
|
if (isUpdatedSpace) {
|
||||||
return space.copyWith(
|
return space.copyWith(
|
||||||
spaceName: updatedSpace.spaceName,
|
spaceName: updatedSpace.spaceName,
|
||||||
icon: updatedSpace.icon,
|
icon: updatedSpace.icon,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (space.children.isNotEmpty) {
|
final hasChildren = space.children.isNotEmpty;
|
||||||
|
if (hasChildren) {
|
||||||
return space.copyWith(
|
return space.copyWith(
|
||||||
children: recusrivelyUpdate(space.children, updatedSpace),
|
children: recusrivelyUpdate(space.children, updatedSpace),
|
||||||
);
|
);
|
||||||
@ -26,7 +28,7 @@ abstract final class SpacesRecursiveHelper {
|
|||||||
List<SpaceModel> spaces,
|
List<SpaceModel> spaces,
|
||||||
String spaceUuid,
|
String spaceUuid,
|
||||||
) {
|
) {
|
||||||
final s = spaces.map((space) {
|
final updatedSpaces = spaces.map((space) {
|
||||||
if (space.uuid == spaceUuid) return null;
|
if (space.uuid == spaceUuid) return null;
|
||||||
if (space.children.isNotEmpty) {
|
if (space.children.isNotEmpty) {
|
||||||
return space.copyWith(
|
return space.copyWith(
|
||||||
@ -35,7 +37,7 @@ abstract final class SpacesRecursiveHelper {
|
|||||||
}
|
}
|
||||||
return space;
|
return space;
|
||||||
}).toList();
|
}).toList();
|
||||||
|
final nonNullSpaces = updatedSpaces.whereType<SpaceModel>().toList();
|
||||||
return s.whereType<SpaceModel>().toList();
|
return nonNullSpaces;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user