Removed deprecated StateStoreViewModel dispatching and reducing

This commit is contained in:
Stefan Ceriu
2022-09-27 11:46:22 +03:00
committed by Stefan Ceriu
parent fc2fdc8ae7
commit 1df0be344d
51 changed files with 109 additions and 275 deletions
@@ -42,13 +42,6 @@ enum RoomAccessTypeChooserCoordinatorAction {
// MARK: - View model
/// Actions to be performed on the `ViewModel` State
enum RoomAccessTypeChooserStateAction {
case updateAccessItems([RoomAccessTypeChooserAccessItem])
case updateShowUpgradeRoomAlert(Bool)
case updateWaitingMessage(String?)
}
/// Actions sent by the`ViewModel` to the `Coordinator`.
enum RoomAccessTypeChooserViewModelAction {
case spaceSelection(String, RoomAccessTypeChooserAccessType)
@@ -17,7 +17,7 @@
import Combine
import SwiftUI
typealias RoomAccessTypeChooserViewModelType = StateStoreViewModel<RoomAccessTypeChooserViewState, RoomAccessTypeChooserStateAction, RoomAccessTypeChooserViewAction>
typealias RoomAccessTypeChooserViewModelType = StateStoreViewModel<RoomAccessTypeChooserViewState, RoomAccessTypeChooserViewAction>
class RoomAccessTypeChooserViewModel: RoomAccessTypeChooserViewModelType, RoomAccessTypeChooserViewModelProtocol {
// MARK: - Properties
@@ -47,10 +47,13 @@ class RoomAccessTypeChooserViewModel: RoomAccessTypeChooserViewModelType, RoomAc
}
private func startObservingService() {
let accessTypePublisher = roomAccessTypeChooserService.accessItemsSubject
.map(RoomAccessTypeChooserStateAction.updateAccessItems)
.eraseToAnyPublisher()
dispatch(actionPublisher: accessTypePublisher)
roomAccessTypeChooserService
.accessItemsSubject
.sink(receiveValue: { [weak self] accessItems in
self?.state.accessItems = accessItems
})
.store(in: &cancellables)
roomAccessTypeChooserService
.roomUpgradeRequiredSubject
.sink { [weak self] isUpgradeRequired in
@@ -59,10 +62,13 @@ class RoomAccessTypeChooserViewModel: RoomAccessTypeChooserViewModelType, RoomAc
}
}
.store(in: &cancellables)
let waitingMessagePublisher = roomAccessTypeChooserService.waitingMessageSubject
.map(RoomAccessTypeChooserStateAction.updateWaitingMessage)
.eraseToAnyPublisher()
dispatch(actionPublisher: waitingMessagePublisher)
roomAccessTypeChooserService.waitingMessageSubject
.sink(receiveValue: { [weak self] message in
self?.state.bindings.waitingMessage = message
self?.state.bindings.isLoading = message != nil
})
.store(in: &cancellables)
}
// MARK: - Public
@@ -77,19 +83,7 @@ class RoomAccessTypeChooserViewModel: RoomAccessTypeChooserViewModelType, RoomAc
cancel()
}
}
override class func reducer(state: inout RoomAccessTypeChooserViewState, action: RoomAccessTypeChooserStateAction) {
switch action {
case .updateAccessItems(let accessItems):
state.accessItems = accessItems
case .updateShowUpgradeRoomAlert(let show):
state.bindings.showUpgradeRoomAlert = show
case .updateWaitingMessage(let message):
state.bindings.waitingMessage = message
state.bindings.isLoading = message != nil
}
}
func handleRoomUpgradeResult(_ result: RoomUpgradeCoordinatorResult) {
switch result {
case .cancel(let roomId):