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] #201 - AddLink MVVM 구조로 변경 #204

Merged
merged 8 commits into from
Sep 28, 2024
Merged

Conversation

mcrkgus
Copy link
Member

@mcrkgus mcrkgus commented Sep 27, 2024

✨ 해결한 이슈

🛠️ 작업내용

  • 기존에 타이머를 사용해서 URL 유효성 검사 및 버튼 활성화 여부를 타이머를 삭제하고 MVVM 구조로 변경했습니다.
  • 원래는 Combine을 사용해서 반응형으로 바꾸려고 했는데 굳이 Combine을 사용하지 않고도 가능해서 일단 보류했습니다.

🖥️ 주요 코드 설명

AddLinkViewModel

  • Input Output 구조로 ViewModel 작성했습니다.
protocol AddLinkViewModelInputs {
    func embedLinkText(_ text: String)}

protocol AddLinkViewModelOutputs {
    var isClearButtonHidden: Bool { get }
    var isNextButtonEnabled: Bool { get }
    var nextButtonBackgroundColor: UIColor { get }
    var textFieldBorderColor: UIColor { get }
    var linkEffectivenessMessage: String? { get }
}

protocol AddLinkViewModelType {
    var inputs: AddLinkViewModelInputs { get }
    var outputs: AddLinkViewModelOutputs { get }
}

AddLinkViewModel

  • Combine 사용하지 않고 didSet으로 updateOutputs을 호출하는 방법으로 해봤습니다. 최선의 방법은 아닌 것 같은데, 더 좋은 방법이 있다면 추천해주세요...
private extension AddLinkViewModel {
    func updateOutputs() {
        let isValid = isValidURL(embedLink)
        isClearButtonHidden = embedLink.isEmpty
        isNextButtonEnabled = !embedLink.isEmpty && isValid
        nextButtonBackgroundColor = isNextButtonEnabled ? .black850 : .gray200
        textFieldBorderColor = isValid ? .clear : UIColor.toasterError
        linkEffectivenessMessage = isValid ? nil : (embedLink.isEmpty ? "링크를 입력해주세요" : "유효하지 않은 형식의 링크입니다.")
    }
    
    func isValidURL(_ urlString: String) -> Bool {
        if (urlString.prefix(8) == "https://") || (urlString.prefix(7) == "http://") {
            return true
        } else {
            return false
        }
    }
}
private var embedLink: String = "" {
        didSet {
            updateOutputs()
        }
    }

📂 참고한 내용

✅ Checklist

  • 필요없는 주석, 프린트문 제거했는지 확인
  • 컨벤션 지켰는지 확인

@mcrkgus mcrkgus added ♻️ Refactor 전면 수정이 있을 때 사용합니다 🩷 가현 가현 선생님 작업 labels Sep 27, 2024
@mcrkgus mcrkgus self-assigned this Sep 27, 2024
Copy link
Member

@mini-min mini-min left a comment

Choose a reason for hiding this comment

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

LGTM 좋네요!
�다음에는 컴바인 쓰러 가봅시다~~👏🏻👏🏻

Copy link
Contributor

@Genesis2010 Genesis2010 left a comment

Choose a reason for hiding this comment

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

Input, output 구조로 만들 때 Combine 을 쓰지 않고 만든 걸 보니 새롭고 좋습니다!
앞으로 같이 Combine 도입하면서 같이 리펙하면 좋을거 같아요!

너무 수고 많으셨습니다!

@mcrkgus mcrkgus merged commit bb0bacf into develop Sep 28, 2024
@mcrkgus mcrkgus deleted the refactor/#201 branch September 29, 2024 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
♻️ Refactor 전면 수정이 있을 때 사용합니다 🩷 가현 가현 선생님 작업
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Refactor] Link Embed MVVM 변경 및 RxSwift 적용
3 participants