Skip to content

Commit 00bfce1

Browse files
committed
fix: Main thread dispatch
1 parent f19e772 commit 00bfce1

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

.swiftpm/xcode/xcshareddata/xcschemes/GoodReactor-Package.xcscheme

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@
7878
ReferencedContainer = "container:">
7979
</BuildableReference>
8080
</TestableReference>
81+
<TestableReference
82+
skipped = "NO">
83+
<BuildableReference
84+
BuildableIdentifier = "primary"
85+
BlueprintIdentifier = "GoodCoordinatorTests"
86+
BuildableName = "GoodCoordinatorTests"
87+
BlueprintName = "GoodCoordinatorTests"
88+
ReferencedContainer = "container:">
89+
</BuildableReference>
90+
</TestableReference>
8191
</Testables>
8292
</TestAction>
8393
<LaunchAction

Sources/LegacyReactor/GoodReactor.swift

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import CombineExt
1111
import SwiftUI
1212

1313
@available(iOS 13.0, *)
14-
private enum MapTables {
14+
@MainActor private enum MapTables {
1515

1616
static let cancellables = WeakMapTable<AnyObject, Set<AnyCancellable>>()
1717
static let currentState = WeakMapTable<AnyObject, Any>()
@@ -91,7 +91,7 @@ nonisolated(unsafe) private var stubKey = "stub"
9191
// MARK: - Default Implementations
9292

9393
@available(iOS 13.0, *)
94-
public extension GoodReactor where Self.ObjectWillChangePublisher == ObservableObjectPublisher {
94+
@MainActor public extension GoodReactor where Self.ObjectWillChangePublisher == ObservableObjectPublisher {
9595

9696
var currentState: State {
9797
get { MapTables.currentState.forceCastedValue(forKey: self, default: initialState) }
@@ -134,28 +134,38 @@ public extension GoodReactor where Self.ObjectWillChangePublisher == ObservableO
134134
///
135135
/// - Returns: A publisher that emits the current state and any subsequent state changes.
136136
func createStateStream() -> AnyPublisher<State, Never> {
137-
let action = self.actionPublisher.receive(on: DispatchQueue.main).eraseToAnyPublisher()
137+
let action = self.actionPublisher
138+
.receive(on: DispatchQueue.main)
139+
.eraseToAnyPublisher()
138140

139141
let mutation = self.transform(action: action)
142+
.receive(on: DispatchQueue.main)
140143
.flatMap { [weak self] action -> AnyPublisher<Mutation, Never> in
141144
guard let `self` = self else { return Empty().eraseToAnyPublisher() }
145+
142146
if let step = self.navigate(action: action) {
143-
self.coordinator.step = step
147+
coordinator.perform(step: step)
144148
}
149+
145150
return self.mutate(action: action).eraseToAnyPublisher()
146151
}
147-
.eraseToAnyPublisher()
152+
.receive(on: DispatchQueue.main)
153+
.eraseToAnyPublisher()
148154

149155
let transformedMutation = self.transform(mutation: mutation)
156+
.receive(on: DispatchQueue.main)
157+
150158
let state = transformedMutation
151159
.scan(self.initialState) { [weak self] state, mutation -> State in
152160
guard let `self` = self else { return state }
153161
return self.reduce(state: state, mutation: mutation)
154162
}
163+
.receive(on: DispatchQueue.main)
155164
.prepend(self.initialState)
156165
.eraseToAnyPublisher()
157166

158167
let transformedState = self.transform(state: state)
168+
.receive(on: DispatchQueue.main)
159169
.handleEvents(receiveOutput: { [weak self] state in
160170
self?.currentState = state
161171
})

0 commit comments

Comments
 (0)