Skip to content

Commit

Permalink
Merge pull request #207 from Team-Ampersand/201-data-fetch-timing-change
Browse files Browse the repository at this point in the history
🔀 :: [#201] 데이터 fetching 시점 변경
  • Loading branch information
baekteun authored Oct 6, 2023
2 parents 0dd4a99 + 28c6ebe commit ea92e33
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class MassageStore: BaseStore {
}

enum Action {
case viewDidLoad
case viewWillAppear
case fetchMassageRankList
}

Expand All @@ -40,8 +40,8 @@ final class MassageStore: BaseStore {
extension MassageStore {
func mutate(state: State, action: Action) -> SideEffect<Mutation, Never> {
switch action {
case .viewDidLoad:
return viewDidLoad()
case .viewWillAppear:
return viewWillAppear()

case .fetchMassageRankList:
return fetchMassageRankList()
Expand All @@ -66,7 +66,7 @@ extension MassageStore {

// MARK: - Mutate
private extension MassageStore {
func viewDidLoad() -> SideEffect<Mutation, Never> {
func viewWillAppear() -> SideEffect<Mutation, Never> {
return self.fetchMassageRankList()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ final class MassageViewController: BaseStoredViewController<MassageStore> {
private let massageNavigationBarLabel = DotoriNavigationBarLabel(text: L10n.Massage.massageTitle)
private let massageTableView = UITableView()
.set(\.backgroundColor, .clear)
.set(\.isHidden, true)
.set(\.separatorStyle, .none)
.set(\.sectionHeaderHeight, 0)
.then {
Expand Down Expand Up @@ -63,8 +62,8 @@ final class MassageViewController: BaseStoredViewController<MassageStore> {
}

override func bindAction() {
viewDidLoadPublisher
.map { Store.Action.viewDidLoad }
viewWillAppearPublisher
.map { Store.Action.viewWillAppear }
.sink(receiveValue: store.send(_:))
.store(in: &subscription)

Expand Down Expand Up @@ -96,11 +95,9 @@ final class MassageViewController: BaseStoredViewController<MassageStore> {
sharedState
.map(\.massageRankList)
.map(\.isEmpty)
.not()
.removeDuplicates()
.sink(with: self, receiveValue: { owner, massageIsEmpty in
owner.massageTableView.isHidden = massageIsEmpty
owner.emptySelfStudyStackView.isHidden = !massageIsEmpty
})
.assign(to: \.isHidden, on: emptySelfStudyStackView)
.store(in: &subscription)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ final class SelfStudyViewController: BaseStoredViewController<SelfStudyStore> {
.set(\.separatorStyle, .none)
.set(\.sectionHeaderHeight, 0)
.set(\.sectionFooterHeight, 0)
.set(\.isHidden, true)
.then {
$0.register(cellType: SelfStudyCell.self)
}
Expand Down Expand Up @@ -77,7 +76,7 @@ final class SelfStudyViewController: BaseStoredViewController<SelfStudyStore> {
}

override func bindAction() {
viewDidLoadPublisher
viewWillAppearPublisher
.merge(with: selfStudyRefreshContorol.controlPublisher(for: .valueChanged).map { _ in })
.map { Store.Action.fetchSelfStudyRank }
.sink(receiveValue: store.send(_:))
Expand All @@ -103,11 +102,9 @@ final class SelfStudyViewController: BaseStoredViewController<SelfStudyStore> {
sharedState
.map(\.selfStudyRankList)
.map(\.isEmpty)
.not()
.removeDuplicates()
.sink(with: self, receiveValue: { owner, selfStudyIsEmpty in
owner.selfStudyTableView.isHidden = selfStudyIsEmpty
owner.emptySelfStudyStackView.isHidden = !selfStudyIsEmpty
})
.assign(to: \.isHidden, on: emptySelfStudyStackView)
.store(in: &subscription)

sharedState
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Combine

public extension Publisher where Output == Bool {
func not() -> Publishers.Map<Self, Bool> {
self.map { !$0 }
}
}

0 comments on commit ea92e33

Please sign in to comment.