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/quest view #113

Merged
merged 2 commits into from
Dec 8, 2022
Merged

Refactor/quest view #113

merged 2 commits into from
Dec 8, 2022

Conversation

jinwoong16
Copy link
Collaborator

๐Ÿ“• Issue Number

Close #112

๐Ÿ“™ ์ž‘์—… ๋‚ด์—ญ

๊ตฌํ˜„ ๋‚ด์šฉ ๋ฐ ์ž‘์—… ํ–ˆ๋˜ ๋‚ด์—ญ

  • ํ€˜์ŠคํŠธ ์ถ”๊ฐ€์‹œ, questview์— ๋ณด์—ฌ์ง€๋Š” ๋กœ์ง ๋ณ€๊ฒฝ

๐Ÿ“˜ ์ž‘์—… ์œ ํ˜•

  • ์‹ ๊ทœ ๊ธฐ๋Šฅ ์ถ”๊ฐ€
  • ๋ฒ„๊ทธ ์ˆ˜์ •
  • ๋ฆฌํŽ™ํ† ๋ง
  • ๋ฌธ์„œ ์—…๋ฐ์ดํŠธ

๐Ÿ“‹ ์ฒดํฌ๋ฆฌ์ŠคํŠธ

  • Merge ํ•˜๋Š” ๋ธŒ๋žœ์น˜๊ฐ€ ์˜ฌ๋ฐ”๋ฅธ๊ฐ€?
  • ์ฝ”๋”ฉ์ปจ๋ฒค์…˜์„ ์ค€์ˆ˜ํ•˜๋Š”๊ฐ€?
  • PR๊ณผ ๊ด€๋ จ์—†๋Š” ๋ณ€๊ฒฝ์‚ฌํ•ญ์ด ์—†๋Š”๊ฐ€?
  • ๋‚ด ์ฝ”๋“œ์— ๋Œ€ํ•œ ์ž๊ธฐ ๊ฒ€ํ† ๊ฐ€ ๋˜์—ˆ๋Š”๊ฐ€?
  • ๋ณ€๊ฒฝ์‚ฌํ•ญ์ด ํšจ๊ณผ์ ์ด๊ฑฐ๋‚˜ ๋™์ž‘์ด ์ž‘๋™ํ•œ๋‹ค๋Š” ๊ฒƒ์„ ๋ณด์ฆํ•˜๋Š” ํ…Œ์ŠคํŠธ๋ฅผ ์ถ”๊ฐ€ํ•˜์˜€๋Š”๊ฐ€?
  • ์ƒˆ๋กœ์šด ํ…Œ์ŠคํŠธ์™€ ๊ธฐ์กด์˜ ํ…Œ์ŠคํŠธ๊ฐ€ ๋ณ€๊ฒฝ์‚ฌํ•ญ์— ๋Œ€ํ•ด ๋งŒ์กฑํ•˜๋Š”๊ฐ€?

๐Ÿ“ PR ํŠน์ด ์‚ฌํ•ญ

PR์„ ๋ณผ ๋•Œ ์ฃผ์˜๊นŠ๊ฒŒ ๋ด์•ผํ•˜๊ฑฐ๋‚˜ ๋งํ•˜๊ณ  ์‹ถ์€ ์ 

  • ํ€˜์ŠคํŠธ๋ฅผ ๋“ฑ๋กํ•˜๋Š” ์ƒํ™ฉ์„ ์ œ์™ธํ•˜๊ณ , QuestView๊ฐ€ usecase๋ฅผ ํ†ตํ•˜์—ฌ ํ€˜์ŠคํŠธ๋ฅผ ๊ฐ€์ ธ์™€์„œ ๋ณด์—ฌ์ฃผ๋Š” ๊ฒฝ์šฐ๋Š” ๋‹ค์Œ ์„ธ๊ฐ€์ง€ ๊ฒฝ์šฐ ์ž…๋‹ˆ๋‹ค.
    1. view๊ฐ€ ์ฒ˜์Œ load ๋˜์—ˆ์„ ๋•Œ
    2. questcell์„ ํด๋ฆญํ•˜์—ฌ, ์—…๋ฐ์ดํŠธ ํ•˜์˜€์„ ๋•Œ
    3. calendarcell์„ ํด๋ฆญํ•˜์—ฌ, ํ•ด๋‹น ๋‚ ์งœ๋กœ ์ด๋™ํ•˜์˜€์„ ๋•Œ
  • ํ€˜์ŠคํŠธ๋ฅผ ๋“ฑ๋กํ•˜๋Š” ์ƒํ™ฉ์—์„œ๋„ QuestView๋ฅผ ์—…๋ฐ์ดํŠธํ•˜์—ฌ ๋ณด์—ฌ์ฃผ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ด ๋•Œ์˜ ๋กœ์ง์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.
    1. ์ง€๊ธˆ ํ˜„์žฌ์œ„์น˜์˜ ๋‚ ์งœ(์บ˜๋ฆฐ๋” ์…€์„ ์„ ํƒํ–ˆ์„ ๋•Œ์˜ ๋‚ ์งœ๋‚˜, ์ฒ˜์Œ ์•ฑ์„ ์ผฐ์„ ๊ฒฝ์šฐ๋Š” ์˜ค๋Š˜)๋ฅผ ๊ธฐ์–ตํ•ฉ๋‹ˆ๋‹ค.
    2. ๋“ฑ๋ก๋˜๋Š” ํ€˜์ŠคํŠธ๋“ค ์ค‘์—์„œ, NotificationCenter๋ฅผ ํ†ตํ•ด ์˜ค๋Š” ๋‚ ์งœ๋“ค ์ค‘ ํ˜„์žฌ์œ„์น˜๋‚ ์งœ๋ฅผ ํฌํ•จํ•˜๋Š” ๋‚ ์งœ๊ฐ€ ์žˆ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.
    3. ์žˆ๋‹ค๋ฉด ํ•ด๋‹น ๋‚ ์งœ๋ฅผ ์ด๋ฒคํŠธ๋กœํ•˜์—ฌ view๋ฅผ ์—…๋ฐ์ดํŠธํ•˜๋Š” output๊ณผ ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค.
final class HomeViewModel {
    private let questUseCase: QuestUseCase
    private var calendarUseCase: CalendarUseCase
    private var currentDate = Date()
....

1๋ฒˆ์— ํ•ด๋‹นํ•˜๋Š” ๋ถ€๋ถ„์ž…๋‹ˆ๋‹ค. currentDate๋ฅผ HomeViewModel์ด ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

        let notification = NotificationCenter
            .default
            .rx
            .notification(.updated)
            .compactMap({ $0.object as? [Date] })
            .withUnretained(self)
            .compactMap { owner, dates in
                let result = dates.filter { date in
                    Calendar.current.isDate(owner.currentDate, inSameDayAs: date)
                }
                
                return !result.isEmpty ? owner.currentDate : nil
            }

2๋ฒˆ์— ํ•ด๋‹นํ•˜๋Š” ๋ถ€๋ถ„์ž…๋‹ˆ๋‹ค. ์ƒ๊ธฐํ–ˆ๋“ฏ, NotificationCenter๋กœ ๋ถ€ํ„ฐ ์˜ค๋Š” Notification์€ ๋“ฑ๋ก๋˜๋Š” ํ€˜์ŠคํŠธ๋“ค์˜ ๋‚ ์งœ๋“ค์„ ์ „์†กํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฅผ ๋น„๊ตํ•ด์„œ ์กด์žฌํ•œ๋‹ค๋ฉด, notification์ด ์ด๋ฒคํŠธ๋ฅผ ๋ฐฉ์ถœํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ ‡์ง€ ์•Š๋‹ค๋ฉด, nil์„ ๋ฐฉ์ถœํ•ด์„œ compactMap์— ๊ฑธ๋Ÿฌ์ ธ, ์ด๋ฒคํŠธ ๋ฐฉ์ถœ๋กœ ์ด์–ด์ง€์ง€ ๋ชปํ•˜๊ฒŒ ํ•ฉ๋‹ˆ๋‹ค.

        let data = Observable
            .merge(updated, input.viewDidLoad, input.daySelected, notification)
            .do(onNext: { [weak self] date in self?.currentDate = date })
            .flatMap(questUseCase.fetch(by:))
            .asDriver(onErrorJustReturn: [])

3๋ฒˆ์— ํ•ด๋‹นํ•˜๋Š” ๋ถ€๋ถ„์ž…๋‹ˆ๋‹ค. merge๋กœ ๋ฌถ์ธ publisher(ํ˜น์€ observable)๋“ค์€ ๋ชจ๋‘ ํ˜„์žฌ์œ„์น˜๋‚ ์งœ์— ํ•ด๋‹นํ•˜๋Š” Date๋ฅผ ๋ฐฉ์ถœํ•ฉ๋‹ˆ๋‹ค. 2๋ฒˆ์—์„œ notification์ด ํ˜„์žฌ์œ„์น˜๋‚ ์งœ๋ฅผ ๋ฐฉ์ถœํ•˜๊ฑฐ๋‚˜ ์•„๋‹ˆ๋ฉด ์•„์˜ˆ ๋ฐฉ์ถœํ•˜์ง€ ์•Š๋Š”๋‹ค๋Š” ๊ฒƒ์„ ์œ ๋…ํ•˜์„ธ์š”.
do() ์˜คํผ๋ ˆ์ดํ„ฐ๋ฅผ ํ†ตํ•ด์„œ ์‚ฌ์ด๋“œ์ดํŽ™ํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. calendar cell ํด๋ฆญ์ด๋ฒคํŠธ(input.daySelected)๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด ์—ฌ๊ธฐ๋ฅผ ํ†ตํ•ด์„œ viewModel์ด ์ฅ๊ณ ์žˆ๋Š” currentDate๋ฅผ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค.



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.

QuestView ์—…๋ฐ์ดํŠธ ๋กœ์ง
1 participant