refactor: [공방] Bundle 아키텍처 전면 개편 - 폴더 구조, ViewModel 분리, 버그 수정 등#47
Merged
refactor: [공방] Bundle 아키텍처 전면 개편 - 폴더 구조, ViewModel 분리, 버그 수정 등#47
Conversation
- 기존에 하나의 Views -> 역할별 분리
- Views를 플로우 기반으로 분리 (Create, Edit, Detail, Shared) - Shared 컴포넌트 파일명/Struct명 간소화 - *SelectableCell → *Cell - KeyringBundleItem → BundleGridItem - BundleItemCustomSheet → DraggableSheet - 파일명 ↔ Struct명 불일치 수정
- BundleViewModel을 의존성주입해서 3개 탭에서 단일 인스턴스 공유 - HomeViewModel에 lastLoadedBundleId 추가, 뭉치 변경 감지함 - 새 뭉치 선택 시 키링 데이터 갱신 안되던 버그 해결
- BundleSheetToggleButtons: 배경/카라비너 시트 토글 버튼 추출 - BundlePurchaseCartItem: 구매 장바구니 아이템 행 추출 - BundleCreateView, BundleEditView+Purchase, BundleEditView+SelectSheet에서 중복 제거
- selectedBackground/selectedCarabiner 로컬 @State 제거 - bundleVM.newSelectedBackground/newSelectedCarabiner 직접 사용 - 불필요한 onChange 동기화 코드 제거 - EditView와 동일한 상태 관리 패턴 적용
- BundleViewModel에 구매 관련 computed properties 추가 (payableItemsCount, totalCartPrice, hasUnpurchasedItems) - BundleViewModel에 isPurchasing 상태 및 purchaseSelectedItems() 메서드 추가 - BundleCreateView에서 로컬 구매 로직 제거, ViewModel 사용으로 변경 - BundleEditView+Purchase에서 중복 구매 로직 제거, ViewModel 사용으로 변경 - BundleEditView에서 로컬 isPurchasing 상태 제거 - Task.sleep을 nanoseconds에서 seconds 스타일로 변경
- MainTabViewModel의 CollectionViewModel을 각 탭에 주입 - HomeTab, WorkshopTab, CollectionTab에서 로컬 인스턴스 생성 제거 - 단일 인스턴스 공유로 메모리 사용 감소 및 데이터 동기화 개선
- +Types: 데이터 구조체 분리 (BackgroundViewData, CarabinerViewData, KeyringInfo) - +Fetch: +LoadData에서 이름 변경 - +Edit: +Sort 병합 - +Purchase: 구매 로직 분리 - +Helpers: 유틸리티 메서드 분리 - +Cache: +ReloadDecision + 이미지 캐시 로직 병합 - +Views: +CaptureScene + 이미지 뷰빌더 병합 - 각 파일에 역할 설명 주석 추가 - 아 힘들어
Member
|
오예~! |
|
고봉밥 PR 레전드 열정길 |
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.
Summary
🎯 PR 내용
1. 폴더 구조 전면 개편
Before:
After:
2. 중복 코드 제거 및 공통 컴포넌트 추출
Create/Edit 화면에서 동일하게 사용되던 UI 컴포넌트들을 Shared로 추출:
BundlePurchaseCartItemBundleSheetToggleButtonsAddKeyringButtonBackgroundCellCarabinerCellKeyringCellSelectBackgroundSheetSelectCarabinerSheetCarabinerPopupDraggableSheet3. BundleViewModel 아키텍처 개선
Before (8개 파일, 책임 혼재):
After (9개 파일, 명확한 책임 분리):
BundleViewModel.swift+Types.swift+Fetch.swift+CRUD.swift+Edit.swift+Purchase.swift+Helpers.swift+Cache.swift+Views.swift4. 비즈니스 로직 View → ViewModel 이동
구매 로직 분리
기존에 View에 흩어져 있던 구매 관련 로직을 ViewModel로 통합:
payableItemsCount- 구매 가능한 아이템 수 계산totalCartPrice- 총 구매 가격 계산hasUnpurchasedItems- 미구매 아이템 존재 여부purchaseSelectedItems()- 실제 구매 처리 (async)isPurchasing- 구매 진행 중 상태State 상태 변수들 → ViewModel 통일
5. CollectionViewModel DI 적용 (Critical Issue)
기존에는 HomeTab, WorkshopTab, CollectionTab에서
각각
CollectionViewModel()을 생성하여 3개의 인스턴스가 존재했음MainTabViewModel에서 단일 인스턴스를 생성하고 각 탭에 주입하는 방식으로 변경
효과:
6. 버그 수정
홈에서 번들 변경 구현 후, 새 뭉치 생성 후 홈 화면 미동기화 문제가 있었다.
refreshBundlesFromBundleVM()호출 추가편집 후 키링 데이터 미갱신
fetchUserKeyring()호출 추가🔗 관련 이슈
✅ 체크리스트