Skip to content

Commit 59ca815

Browse files
committed
🐛 :: (#446) WritableReviewReactor의 state 재귀 참조로 인한 크래시 수정
transform(mutation:)에서 아직 생성되지 않은 state를 참조해 무한 재귀로 스택 오버플로가 발생하던 문제를 scan으로 대체해 해결. MyPageFlow의 네트워크 응답 구독도 메인스레드로 옮기고 disposeBag에 보관.
1 parent 4e6f09d commit 59ca815

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

Projects/Flow/Sources/MyPage/MyPageFlow.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import UIKit
22
import Presentation
33
import Swinject
44
import RxFlow
5+
import RxSwift
56
import Domain
67
import Core
78

89
public final class MyPageFlow: Flow {
910
public let container: Container
1011
private let rootViewController = BaseNavigationController()
12+
private let disposeBag = DisposeBag()
1113
public var root: Presentable {
1214
return rootViewController
1315
}
@@ -85,11 +87,13 @@ extension MyPageFlow {
8587
let view = root as? WritableReviewViewController
8688
view?.reactor.companyID = id
8789
if let useCase = self.container.resolve(FetchCompanyInfoDetailUseCase.self) {
88-
_ = useCase.execute(id: id)
90+
useCase.execute(id: id)
91+
.observe(on: MainScheduler.instance)
8992
.subscribe(onSuccess: { entity in
9093
view?.reactor.companyName = entity.companyName
9194
view?.navigationItem.title = entity.companyName
9295
}, onFailure: { _ in })
96+
.disposed(by: self.disposeBag)
9397
}
9498
self.rootViewController.pushViewController(
9599
view!, animated: true

Projects/Presentation/Sources/WritableReview/WritableReviewReactor.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@ public final class WritableReviewReactor: BaseReactor, Stepper {
3737
extension WritableReviewReactor {
3838
public func transform(mutation: Observable<Mutation>) -> Observable<Mutation> {
3939
let interviewReviewMutation = interviewReviewInfo
40-
.withLatestFrom(state.map { $0.qnaInfoList }) { newInfo, oldList -> [QnAEntity] in
41-
var newList = oldList
42-
newList.append(newInfo)
43-
return newList
40+
.scan([QnAEntity]()) { oldList, newInfo in
41+
oldList + [newInfo]
4442
}
4543
.map { Mutation.setQnAInfoList($0) }
4644

0 commit comments

Comments
 (0)