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] MVVM 리팩토링 (#7) #8

Merged
merged 13 commits into from
Jun 28, 2024
Merged

[REFACTOR] MVVM 리팩토링 (#7) #8

merged 13 commits into from
Jun 28, 2024

Conversation

seuriseuljjeok
Copy link
Collaborator

@seuriseuljjeok seuriseuljjeok commented Jun 2, 2024

🔥Pull requests

⛳️ 작업한 브랜치

👷 작업한 내용

  • MVVM 리팩토링

🚨 참고 사항

1. UICollectionViewDataSource는 어디서 처리할까

  • 처음엔 UICollectionViewDataSource는 주로 셀의 데이터를 초기화하거나 설정해주는 역할들을 하기 때문에 ViewModel로 분리해주어야 한다고 생각했고 그렇게 구현했습니다
  • 하지만 UITableViewDataSource에서는 온전히 데이터를 로딩하거나 가공하는 것이 아니고 UI와 관련된 작업들도 종종 이루어지는데 이러한 작업들은 뷰컨에서 처리하기도 하고, 데이터를 �컬뷰에 바인딩하는 것도 뷰컨이 하는 것이 더 자연스러울 것 같다고 판단해서 다시 수정했습니다🥹

📟 관련 이슈

Copy link

@FpRaArNkK FpRaArNkK left a comment

Choose a reason for hiding this comment

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

와우 PR이 3개네요... 리뷰 열심히 달려보겠습니다 🔥🔥

Comment on lines +12 to +27
static func calculateDate() -> String {
let today = Date()
let calendar = Calendar.current
var dateComponents = DateComponents()
dateComponents.day = -1

if let oneDayAgo = calendar.date(byAdding: dateComponents, to: today) {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyyMMdd"

let oneDayAgoString = dateFormatter.string(from: oneDayAgo)
return oneDayAgoString
} else {
return ""
}
}

Choose a reason for hiding this comment

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

let yesterday = calendar.date(byAdding: .day, value: -1, to: Date())
이런 방법도 있답니다!

추후 범용성을 생각한다면 매개변수로 calculate할 Int 값을 받아 value로 넣어줘도 좋을 것 같아요!

Comment on lines +10 to +28
final class ObservablePattern<T> { // --- a

var value: T? { // --- b
didSet {
self.listener?(value)
}
}

init(_ value: T?) {
self.value = value
}

private var listener: ((T?) -> Void)? // --- c

func bind(_ listener: @escaping (T?) -> Void) {
listener(value) // 생략 가능, 여기선 시작되는 순간부터 초기값을 갖고 동작하기 위해 사용
self.listener = listener
}
}

Choose a reason for hiding this comment

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

Observable을 직접 구현하셨군요! bbb

Choose a reason for hiding this comment

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

ViewModel에서 관리하는 비즈니스 로직은 UI 조작부분을 제외하고 잡으신 것 같아요!
MVVM 리팩토링에서 너무 좋은 방법인 것 같습니다 bbb

Comment on lines +36 to +38
var nickname: String? = nil

private let loginViewModel: LoginViewModel = LoginViewModel()

Choose a reason for hiding this comment

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

ViewModel에서 데이터를 분리하신 이유가 있을까요??

Comment on lines +168 to +190
func setViewModel() {
mainViewModel.didUpdateNetworkResult.bind { [weak self] isSuccess in
guard let isSuccess else { return }
if isSuccess {
self?.mainCollectionView.reloadData()
}
}

mainViewModel.didChangeLoadingIndicator.bind { [weak self] isLoading in
guard let isLoading else { return }
if isLoading {
self?.loadingIndicator.startAnimating()
} else {
self?.loadingIndicator.stopAnimating()
}
}
}

func getMovieInfo() {
if mainViewModel.getMovieInfo() {
self.mainCollectionView.reloadData()
}
}

Choose a reason for hiding this comment

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

ViewModel의 Stream Subscribe 로직들 너무 좋은 것 같습니다! bb

Choose a reason for hiding this comment

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

ViewModel에서 Delegate 처리해주는 게 너무 좋습니다 bb

@seuriseuljjeok seuriseuljjeok merged commit 9fdd74b into main Jun 28, 2024
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.

[REFACTOR] MVVM 리팩토링
2 participants