-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
와우 PR이 3개네요... 리뷰 열심히 달려보겠습니다 🔥🔥
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 "" | ||
} | ||
} |
There was a problem hiding this comment.
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로 넣어줘도 좋을 것 같아요!
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 | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Observable을 직접 구현하셨군요! bbb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ViewModel에서 관리하는 비즈니스 로직은 UI 조작부분을 제외하고 잡으신 것 같아요!
MVVM 리팩토링에서 너무 좋은 방법인 것 같습니다 bbb
var nickname: String? = nil | ||
|
||
private let loginViewModel: LoginViewModel = LoginViewModel() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ViewModel에서 데이터를 분리하신 이유가 있을까요??
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() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ViewModel의 Stream Subscribe 로직들 너무 좋은 것 같습니다! bb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ViewModel에서 Delegate 처리해주는 게 너무 좋습니다 bb
🔥Pull requests
⛳️ 작업한 브랜치
👷 작업한 내용
🚨 참고 사항
1. UICollectionViewDataSource는 어디서 처리할까
📟 관련 이슈