Skip to content

Conversation

jungseokyoung-cloud
Copy link
Collaborator

@jungseokyoung-cloud jungseokyoung-cloud commented Dec 6, 2024

관련 이슈

✅ 완료 및 수정 내역

  • 나가기 기능 구현
  • Coordinator로 리팩토링

📝 리뷰 노트


우선, 회의에서 이야기 했던 대로 다음과 같은 상황을 위해 Coordinator를 도입하게 되었습니다. - 초기화 시점이 AppRoot시점이다. (필요한 시점에 초기화 불가) - 나가기 플로우의 복잡성 - 초기화 시점이 AppRoot이다 보니, CRDT의 피어들의 ID를 전달 할땐, 연결이 이루어지지 않음.

Coordinator 적용

Coordinator는 다음과 같이 구성됩니다.
우선, Coordinator에서 필요한 객체들의 바구니인 Container가 존재합니다.
이 Container는 Dependency를 통해 상위 Coordinator에게 필요한 의존성을 요구할 수 있습니다.

public protocol ConnectionDependency {
    var videoListContaiable: VideoListContainable { get }
    var browsingUseCase: BrowsingUserUseCaseInterface { get }
}

public protocol ConnectionContainable {
    func coordinator(listener: ConnectionListener) -> Coordinatable
}

public final class ConnectionContainer:
    Container<ConnectionDependency>, ConnectionContainable {
    public func coordinator(listener: ConnectionListener) -> Coordinatable {
        let viewModel = ConnectionViewModel(usecase: dependency.browsingUseCase)
        
        let coordinator = ConnectionCoordinator(
            viewModel: viewModel,
            videoListContainable: dependency.videoListContaiable
        )
        coordinator.listener = listener
        
        return coordinator
    }
}

다음과 같이 부모는 자식의 Dependecy를 채택해야 합니다.

final class MainContainer: ConnectionDependency {
   // MARK: - Containable
    var videoListContaiable: VideoListContainable {
        return VideoListContainer(dependency: self)
    }

  // MARK: - UseCase
    var browsingUseCase: BrowsingUserUseCaseInterface {
        return BrowsingUserUseCase(repository: browsingUserRepository)
    }
}

이때, 부모 타입에서는 Container만 들고 있으면 coordinator()라는 메서드를 통해 코디네이터를 생성할 수 있습니다.

public func coordinator(listener: ConnectionListener) -> Coordinatable {
        let viewModel = ConnectionViewModel(usecase: dependency.browsingUseCase)
        
        let coordinator = ConnectionCoordinator(
            viewModel: viewModel,
            videoListContainable: dependency.videoListContaiable
        )
        coordinator.listener = listener
        
        return coordinator
}

또한, Coordinator는 트리구조를 형성하고 있기 때문에 Listner를 통해 이벤트를 전달할 수 있습니다.

public protocol ConnectionListener: AnyObject { }

final class ConnectionCoordinator: Coordinator, ConnectionCoordinatable {
    weak var listener: ConnectionListener?

현재 하나의 ViewController에 top과 bottom을 나누는 구조로 되어있습니다.
top의 경우 그룹의 정보 뷰로 고정이지만 bottom에서는 뷰의 전환이 일어납니다.

top에서 나가기 버튼을 클릭시 bottom에서 첫 화면으로 나가야 합니다.
하지만, Coordinator에선 top에서 listener를 통해 상위로 전달할 수 있습니다.
이때 상위는 bottom의 메서드를 호출 시켜 나가기를 구현할 수 있게 되었습니다.

Copy link
Collaborator

@around-forest around-forest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다 ㅠㅠ

Copy link
Collaborator

@051198Hz 051198Hz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생 많으셨습니다 ~! 잠은 주무셨나요ㅠㅜ

Copy link
Collaborator

@LURKS02 LURKS02 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다 !!!

@jungseokyoung-cloud jungseokyoung-cloud merged commit 7930a40 into develop Dec 6, 2024
6 checks passed
@jungseokyoung-cloud jungseokyoung-cloud deleted the feature/#87 branch December 6, 2024 01:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

<나가기>버튼을 눌렀을 때 연결화면으로 돌아간다

4 participants