Skip to content

Commit

Permalink
Merge pull request #280 from boostcampwm-2024/task/singletone_review
Browse files Browse the repository at this point in the history
task singletone관련 review를 반영
  • Loading branch information
INYEKIM authored Dec 2, 2024
2 parents 7817012 + 436c2f9 commit 6305226
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 16 deletions.
8 changes: 6 additions & 2 deletions Projects/App/Sources/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,21 @@ extension SceneDelegate {
let liveStreamFactoryImpl = LiveStreamViewControllerFactoryImpl(fetchBroadcastUseCase: fetchBroadcastUseCase)
DIContainer.shared.register(LiveStreamViewControllerFactory.self, dependency: liveStreamFactoryImpl)

let broadcastState: BroadcastState = BroadcastState.shared

let settingFactoryImpl = SettingViewControllerFactoryImpl(
fetchChannelInfoUsecase: fetchChannelInfoUsecaseImpl,
makeBroadcastUsecase: makeBroadcastUsecaseImpl,
deleteBroadCastUsecase: deleteBroadCastUsecaseImpl
deleteBroadCastUsecase: deleteBroadCastUsecaseImpl,
broadcastState: broadcastState
)
DIContainer.shared.register(SettingViewControllerFactory.self, dependency: settingFactoryImpl)

let broadcastViewControllerFactory = BroadcastViewControllerFactoryImpl(
fetchChannelInfoUsecase: fetchChannelInfoUsecaseImpl,
makeBroadcastUsecase: makeBroadcastUsecaseImpl,
deleteBroadCastUsecase: deleteBroadCastUsecaseImpl
deleteBroadCastUsecase: deleteBroadCastUsecaseImpl,
broadcastState: broadcastState
)
DIContainer.shared.register(BroadcastViewControllerFactory.self, dependency: broadcastViewControllerFactory)
}
Expand Down
4 changes: 3 additions & 1 deletion Projects/Features/MainFeature/Demo/Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
let mockmakeBroadcastUsecase = MockMakeBroadcastUsecaseImpl()
let mockFetchAllBroadcastUsecase = MockFetchAllBroadcastUsecaseImpl()
let mockDeleteBroadcastUsecase = MockDeleteBroadcastUsecaseImpl()
let mockBroadcastState = MockBroadcastState()
let viewModel = BroadcastCollectionViewModel(
fetchChannelListUsecase: mockFetchChannelListUsecase,
fetchAllBroadcastUsecase: mockFetchAllBroadcastUsecase
fetchAllBroadcastUsecase: mockFetchAllBroadcastUsecase,
broadcastState: mockBroadcastState
)
let mockFactory = MockLiveStreamViewControllerFractoryImpl()
let viewController = BroadcastCollectionViewController(viewModel: viewModel, factory: mockFactory)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Combine

import MainFeatureInterface

final class MockBroadcastState: BroadcastStateProtocol {
var isBroadcasting: PassthroughSubject<Bool, Never> = .init()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Combine

public protocol BroadcastStateProtocol {
var isBroadcasting: PassthroughSubject<Bool, Never> { get }
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@ public struct BroadcastViewControllerFactoryImpl: BroadcastViewControllerFactory
private let fetchChannelInfoUsecase: any FetchChannelInfoUsecase
private let makeBroadcastUsecase: any MakeBroadcastUsecase
private let deleteBroadCastUsecase: any DeleteBroadcastUsecase
private let broadcastState: BroadcastState

public init(fetchChannelInfoUsecase: any FetchChannelInfoUsecase, makeBroadcastUsecase: any MakeBroadcastUsecase, deleteBroadCastUsecase: any DeleteBroadcastUsecase) {
public init(fetchChannelInfoUsecase: any FetchChannelInfoUsecase, makeBroadcastUsecase: any MakeBroadcastUsecase, deleteBroadCastUsecase: any DeleteBroadcastUsecase, broadcastState: BroadcastState) {
self.fetchChannelInfoUsecase = fetchChannelInfoUsecase
self.makeBroadcastUsecase = makeBroadcastUsecase
self.deleteBroadCastUsecase = deleteBroadCastUsecase
self.broadcastState = broadcastState
}

public func make() -> UIViewController {
let viewModel = SettingViewModel(
fetchChannelInfoUsecase: fetchChannelInfoUsecase,
makeBroadcastUsecase: makeBroadcastUsecase,
deleteBroadCastUsecase: deleteBroadCastUsecase
deleteBroadCastUsecase: deleteBroadCastUsecase,
broadcastState: broadcastState
)

return BroadcastViewController(viewModel: viewModel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@ public struct SettingViewControllerFactoryImpl: SettingViewControllerFactory {
private let fetchChannelInfoUsecase: any FetchChannelInfoUsecase
private let makeBroadcastUsecase: any MakeBroadcastUsecase
private let deleteBroadCastUsecase: any DeleteBroadcastUsecase
private let broadcastState: BroadcastState

public init(fetchChannelInfoUsecase: any FetchChannelInfoUsecase, makeBroadcastUsecase: any MakeBroadcastUsecase, deleteBroadCastUsecase: any DeleteBroadcastUsecase) {
public init(fetchChannelInfoUsecase: any FetchChannelInfoUsecase, makeBroadcastUsecase: any MakeBroadcastUsecase, deleteBroadCastUsecase: any DeleteBroadcastUsecase, broadcastState: BroadcastState) {
self.fetchChannelInfoUsecase = fetchChannelInfoUsecase
self.makeBroadcastUsecase = makeBroadcastUsecase
self.deleteBroadCastUsecase = deleteBroadCastUsecase
self.broadcastState = broadcastState
}

public func make() -> UIViewController {
let viewModel = SettingViewModel(
fetchChannelInfoUsecase: fetchChannelInfoUsecase,
makeBroadcastUsecase: makeBroadcastUsecase,
deleteBroadCastUsecase: deleteBroadCastUsecase
deleteBroadCastUsecase: deleteBroadCastUsecase,
broadcastState: broadcastState
)

return SettingUIViewController(viewModel: viewModel)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import Combine

final class BroadcastState {
static let shared = BroadcastState()
import MainFeatureInterface

public final class BroadcastState: BroadcastStateProtocol {
public static let shared = BroadcastState()

public let isBroadcasting: PassthroughSubject<Bool, Never> = .init()

let isBroadcasting: PassthroughSubject<Bool, Never> = .init()
private init() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import UIKit
import BaseFeature
import DesignSystem
import EasyLayoutModule
import MainFeatureInterface

public final class SettingUIViewController: BaseViewController<SettingViewModel> {
deinit {
Expand All @@ -21,9 +22,23 @@ public final class SettingUIViewController: BaseViewController<SettingViewModel>

private var broadcastPicker = RPSystemBroadcastPickerView()

private let broadcastState: BroadcastStateProtocol

private let viewModelInput = SettingViewModel.Input()
private var cancellables = Set<AnyCancellable>()

public init(
viewModel: SettingViewModel,
broadcastState: BroadcastStateProtocol = BroadcastState.shared
) {
self.broadcastState = broadcastState
super.init(viewModel: viewModel)
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

public override func observeValue(
forKeyPath keyPath: String?,
of object: Any?,
Expand Down Expand Up @@ -149,7 +164,7 @@ public final class SettingUIViewController: BaseViewController<SettingViewModel>
}

private func didStartBroadCast() {
BroadcastState.shared.isBroadcasting.send(true)
broadcastState.isBroadcasting.send(true)
dismiss(animated: true)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import UIKit
import BaseFeatureInterface
import BroadcastDomainInterface
import LiveStationDomainInterface
import MainFeatureInterface

public class BroadcastCollectionViewModel: ViewModel {
public struct Input {
Expand All @@ -22,6 +23,8 @@ public class BroadcastCollectionViewModel: ViewModel {
private let fetchChannelListUsecase: any FetchChannelListUsecase
private let fetchAllBroadcastUsecase: any FetchAllBroadcastUsecase

private let broadcastState: BroadcastStateProtocol

private var cancellables = Set<AnyCancellable>()

private let extensionBundleID = "kr.codesquad.boostcamp9.Shook.BroadcastUploadExtension"
Expand All @@ -30,10 +33,12 @@ public class BroadcastCollectionViewModel: ViewModel {

public init(
fetchChannelListUsecase: FetchChannelListUsecase,
fetchAllBroadcastUsecase: FetchAllBroadcastUsecase
fetchAllBroadcastUsecase: FetchAllBroadcastUsecase,
broadcastState: BroadcastStateProtocol = BroadcastState.shared
) {
self.fetchChannelListUsecase = fetchChannelListUsecase
self.fetchAllBroadcastUsecase = fetchAllBroadcastUsecase
self.broadcastState = broadcastState
}

public func transform(input: Input) -> Output {
Expand All @@ -49,7 +54,7 @@ public class BroadcastCollectionViewModel: ViewModel {
}
.store(in: &cancellables)

BroadcastState.shared.isBroadcasting
broadcastState.isBroadcasting
.sink { [weak self] isBroadcasting in
if isBroadcasting {
self?.output.showBroadcastUIView.send()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Foundation
import BaseFeatureInterface
import BroadcastDomainInterface
import LiveStationDomainInterface
import MainFeatureInterface

public class SettingViewModel: ViewModel {
public struct Input {
Expand All @@ -25,6 +26,8 @@ public class SettingViewModel: ViewModel {
private let makeBroadcastUsecase: any MakeBroadcastUsecase
private let deleteBroadCastUsecase: any DeleteBroadcastUsecase

private let broadcastState: BroadcastStateProtocol

private var broadcastName: String = ""
private var channelDescription: String = ""

Expand All @@ -41,11 +44,13 @@ public class SettingViewModel: ViewModel {
public init(
fetchChannelInfoUsecase: FetchChannelInfoUsecase,
makeBroadcastUsecase: MakeBroadcastUsecase,
deleteBroadCastUsecase: DeleteBroadcastUsecase
deleteBroadCastUsecase: DeleteBroadcastUsecase,
broadcastState: BroadcastState
) {
self.fetchChannelInfoUsecase = fetchChannelInfoUsecase
self.makeBroadcastUsecase = makeBroadcastUsecase
self.deleteBroadCastUsecase = deleteBroadCastUsecase
self.broadcastState = broadcastState
}

public func transform(input: Input) -> Output {
Expand Down Expand Up @@ -102,8 +107,8 @@ public class SettingViewModel: ViewModel {
.eraseToAnyPublisher()
}
.sink { _ in
} receiveValue: { _ in
BroadcastState.shared.isBroadcasting.send(false)
} receiveValue: { [weak self] _ in
self?.broadcastState.isBroadcasting.send(false)
}
.store(in: &cancellables)

Expand Down

0 comments on commit 6305226

Please sign in to comment.