[#439] MainView의 destination ViewModel 생성 및 생명주기를 개선한다#446
Merged
Conversation
MainViewCoordinator가 생성하는 하위 화면 ViewModel을 단일 인스턴스 기준으로 보관하도록 변경 - TodoListViewModel은 현재 category와 일치할 때 기존 인스턴스 재사용 - TodoDetailViewModel은 현재 todoId와 showEditButton 조건이 일치할 때 기존 인스턴스 재사용 - category별 dictionary와 todoId별 dictionary 제거 - ViewModel이 가진 생성 기준 값을 재사용 조건으로 활용하여 코디네이터의 별도 key 상태 제거 - compact/regular 전환으로 같은 하위 화면이 재생성될 때 기존 ViewModel 인스턴스를 유지하는 구조
Contributor
There was a problem hiding this comment.
Code Review
This pull request refactors ViewModel instantiation by moving factory methods from MainView to MainViewCoordinator and implementing a basic caching mechanism for TodoListViewModel and TodoDetailViewModel. Additionally, the category property in TodoListViewModel was moved from the State struct directly into the ViewModel class. Feedback was provided regarding the single-instance caching strategy in the coordinator, noting that it may cause state loss when navigating through multiple instances of the same view type in a NavigationStack. An ID-based caching strategy was suggested as a more robust alternative to preserve state during navigation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 연관된 이슈
🎯 의도
📝 작업 내용
📌 요약
🔍 상세
make~ViewModel()생성 로직을 MainViewCoordinator로 이동viewModel.state.category에서viewModel.category로 변경