Skip to content

Commit

Permalink
fix : OrganizingSentenceRepository 생성 위치 수정 #7
Browse files Browse the repository at this point in the history
- AddArticleComponent 에 OrganizingSentenceRepositoryImp 생성
- 잘못된 위치에서 생성된 OrganizingSentenceRepository 코드 제거
- AddArticle 하위 RIB 들이 이를 공유하도록 설정
  • Loading branch information
wongbingg committed Aug 8, 2023
1 parent 14320e3 commit 5673357
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 40 deletions.
12 changes: 3 additions & 9 deletions Particle/Particle/LoggedIn/LoggedInBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,13 @@
import RIBs

protocol LoggedInDependency: Dependency {
// TODO: Make sure to convert the variable into lower-camelcase.
var LoggedInViewController: LoggedInViewControllable { get }
var organizingSentenceRepository: OrganizingSentenceRepository { get }
var loggedInViewController: LoggedInViewControllable { get }
}

final class LoggedInComponent: Component<LoggedInDependency>, MainDependency {

// TODO: Make sure to convert the variable into lower-camelcase.
fileprivate var LoggedInViewController: LoggedInViewControllable {
return dependency.LoggedInViewController
}
var organizingSentenceRepository: OrganizingSentenceRepository {
return dependency.organizingSentenceRepository
fileprivate var loggedInViewController: LoggedInViewControllable {
return dependency.loggedInViewController
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ public protocol OrganizingSentenceRepository {
}

public final class OrganizingSentenceRepositoryImp: OrganizingSentenceRepository {
public var sentenceFile: RxSwift.BehaviorSubject<[String]> {
sentenceSubject
}

public var sentenceFile: BehaviorSubject<[String]> = .init(value: [])

private let sentenceSubject = BehaviorSubject<[String]>(value: [
"그렇게 쓴 글은 매일 사회관계망서비스(SNS)에 남기기도 하고, 모아서 책으로 내기도 한다.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ protocol AddArticleDependency: Dependency {

final class AddArticleComponent: Component<AddArticleDependency> {

var repository = OrganizingSentenceRepositoryImp()
// TODO: Make sure to convert the variable into lower-camelcase.
fileprivate var addArticleViewController: ViewControllable {
return dependency.addArticleViewController
Expand Down Expand Up @@ -63,6 +64,6 @@ extension AddArticleComponent: PhotoPickerDependency,
SetAdditionalInformationDependency {

var organizingSentenceRepository: OrganizingSentenceRepository {
return OrganizingSentenceRepositoryImp() //FIXME: ??
return repository
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import RIBs
import Photos

protocol SelectSentenceDependency: Dependency {
// TODO: Declare the set of dependencies required by this RIB, but cannot be
// created by this RIB.
var organizingSentenceRepository: OrganizingSentenceRepository { get }
}

final class SelectSentenceComponent: Component<SelectSentenceDependency> {

// TODO: Declare 'fileprivate' dependencies that are only used by this RIB.
fileprivate var organizingSentenceRepository: OrganizingSentenceRepository {
return dependency.organizingSentenceRepository
}
}

// MARK: - Builder
Expand All @@ -33,7 +33,7 @@ final class SelectSentenceBuilder: Builder<SelectSentenceDependency>, SelectSent
func build(withListener listener: SelectSentenceListener, images: [PHAsset]) -> SelectSentenceRouting {
let component = SelectSentenceComponent(dependency: dependency)
let viewController = SelectSentenceViewController(selectedImages: images)
let interactor = SelectSentenceInteractor(presenter: viewController)
let interactor = SelectSentenceInteractor(presenter: viewController, repository: component.organizingSentenceRepository)
interactor.listener = listener

let editSentenceBuilder = EditSentenceBuilder(dependency: component)
Expand All @@ -46,8 +46,4 @@ final class SelectSentenceBuilder: Builder<SelectSentenceDependency>, SelectSent
}
}

extension SelectSentenceComponent: EditSentenceDependency, OrganizingSentenceDependency {
var organizingSentenceRepository: OrganizingSentenceRepository {
OrganizingSentenceRepositoryImp()
}
}
extension SelectSentenceComponent: EditSentenceDependency { }
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ protocol SelectSentenceListener: AnyObject {
final class SelectSentenceInteractor: PresentableInteractor<SelectSentencePresentable>,
SelectSentenceInteractable,
SelectSentencePresentableListener {

weak var router: SelectSentenceRouting?
weak var listener: SelectSentenceListener?

private var organizingSentenceRepository: OrganizingSentenceRepository

// TODO: Add additional dependencies to constructor. Do not perform any logic
// in constructor.
override init(presenter: SelectSentencePresentable) {
init(presenter: SelectSentencePresentable, repository: OrganizingSentenceRepository) {
self.organizingSentenceRepository = repository
super.init(presenter: presenter)
presenter.listener = self
}
Expand All @@ -56,9 +59,14 @@ final class SelectSentenceInteractor: PresentableInteractor<SelectSentencePresen
router?.attachEditSentence(with: text)
}

func dismissEditSentence() {
func dismissEditSentence(with text: String) {
guard var list = try? organizingSentenceRepository.sentenceFile.value() else {
Console.error("\(#function) value 를 가져올 수 없습니다.")
return
}
list.append(text)
organizingSentenceRepository.sentenceFile.onNext(list)
router?.detachEditSentence()
listener?.pushToOrganizingSentence()
}

func backButtonTapped() {
Expand Down
10 changes: 2 additions & 8 deletions Particle/Particle/Main/MainBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@

import RIBs

protocol MainDependency: Dependency {
var organizingSentenceRepository: OrganizingSentenceRepository { get }
}
protocol MainDependency: Dependency { }

final class MainComponent: Component<MainDependency>, OrganizingSentenceDependency, SetAdditionalInformationDependency {
var organizingSentenceRepository: OrganizingSentenceRepository {
dependency.organizingSentenceRepository
}
}
final class MainComponent: Component<MainDependency> { }

// MARK: - Builder

Expand Down
6 changes: 1 addition & 5 deletions Particle/Particle/Root/RootComponent+LoggedIn.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ protocol RootDependencyLoggedIn: Dependency {

extension RootComponent: LoggedInDependency {

var LoggedInViewController: LoggedInViewControllable {
var loggedInViewController: LoggedInViewControllable {
return rootViewController
}

var organizingSentenceRepository: OrganizingSentenceRepository {
return OrganizingSentenceRepositoryImp()
}
}

0 comments on commit 5673357

Please sign in to comment.