Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] Observable 적용 + 피드백 반영 #33

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

yurim830
Copy link
Collaborator

@yurim830 yurim830 commented Jan 3, 2025

🔍 What is the PR?

  • Login 기능에 Observable을 적용했습니다.
  • ViewModel과 View의 기능을 더 명확하게 분리했습니다.

💭 Related Issues

📝 변경 사항

  • LoginInfo 구조체를 새로 생성함으로써 LoginDTO는 네트워킹에서만 사용하도록 했어요.
  • 사용자가 TextField에 입력한 텍스트를 받아오는 방식을 수정했어요.
    • 기존: View에서 TextField가 비어있는지를 확인하는 로직을 거쳐 LoginInfo 형태로 데이터를 생성하여 반환함
    • 현재: getUsername(), getPassword() 함수를 생성했고, Controller에서 이 함수들을 호출하여 데이터 체크 및 LoginInfo 형식으로 변환하여 사용함
  • Observable을 활용하는 방향으로 자동로그인 로직을 수정했어요.

🙏 To Reviewers

  • 피드백 환영입니다. 감사합니다!

@yurim830 yurim830 added the 리팩토링 Refactoring label Jan 3, 2025
@yurim830 yurim830 requested review from Ohjackson and cirtuare January 3, 2025 18:25
@yurim830 yurim830 self-assigned this Jan 3, 2025
Copy link

@cirtuare cirtuare left a comment

Choose a reason for hiding this comment

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

LGTM ~

Comment on lines 148 to 158
extension LoginView {

func getUsername() -> String? {
return usernameTextField.text
}

func bind(username: String, password: String, autoLogin: Bool) {
usernameTextField.text = username
passwordTextField.text = password
updateAutoLoginCheckButton(autoLogin: autoLogin)
func getPassword() -> String? {
return passwordTextField.text
}

}
Copy link

Choose a reason for hiding this comment

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

이렇게 처리해줘도 좋지만, 굳이 이렇게 처리할 필요는 없어요 ~!
저는 개인적으로 뷰컨에서 loginView.passwordTextField.text 으로 불러오는 방식을 조금 더 선호합니다! (그러면 뷰에서 passwordTextField가 private이 아니게만 조정해주면 됩니당) 굳이 멍청해야 하는 뷰가 데이터 전달 함수를 가지고 있을 필요가 없다구 생각해요

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

오호.. 이렇게 생각하는 것도 일리가 있네요..! @cirtuare

혹시 캡슐화를 강화하기 위해 loginView.usernameTextField를 private으로 제한하고
getUsername(), setUsername(text:), setUsernameDelegate(_:) 메소드를 만드는 것에 대해서는 어떻게 생각하시나요?

// LoginView
    func getUsername() -> String? {
        return usernameTextField.text
    }
    
    func setUsername(text: String?) {
        usernameTextField.text = text
    }

    func setUsernameDelegate(_ delegate: UITextFieldDelegate) {
        usernameTextField.delegate = delegate
    }
// LoginViewController
    override func bind() {
        loginViewModel.usernameBinding.bind { [weak self] username in
            guard let self = self else { return }
            loginView.setUsername(text: username)
        }
        ...
    }

    private func handleLoginInfo() -> LoginInfo? {
        guard let username = loginView.getUsername(),
              let password = loginView.getPassword(),
        ...
    }

Copy link

Choose a reason for hiding this comment

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

사실 일회성이라면 굳이.. 싶긴 한 부분이지만, getUsername / setUsername 메소드를 쓸 일이 많으면 이렇게 짤 것 같아요 !!
또는 extension으로, textfield의 text를 get / set 하는 함수를 만들어두고 두고두고 활용하는 방식을 도입해도 될 것 같습니다. 전 뷰에 걸쳐 textfield의 text를 많이 가져오고 세팅하니까요 ~ !!

Copy link
Collaborator Author

@yurim830 yurim830 Jan 5, 2025

Choose a reason for hiding this comment

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

오호... 답변 감사합니다!! 도움이 됐어요😁

Comment on lines +68 to +69
guard let username = loginView.getUsername(),
let password = loginView.getPassword(),
Copy link

Choose a reason for hiding this comment

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

전 리뷰를 적용한다면, 여기서 그냥 let password = loginView.passwordTextField.text으로 접근해주면 돼용

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
리팩토링 Refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Refactor] Observable 패턴 적용 - login 뷰
2 participants