Skip to content

Commit

Permalink
Always dispatch on main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimillian committed Jul 22, 2019
1 parent 9f82e31 commit 0fc5d59
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Sources/SwiftUIFlux/Store.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ final public class Store<State: FluxState>: BindableObject {
}

public func dispatch(action: Action) {
dispatchFunction(action)
DispatchQueue.main.async {
self.dispatchFunction(action)
}
}

private func _dispatch(action: Action) {
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftUIFluxTests/SwiftUIFluxTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func testReducer(state: TestState, action: Action) -> TestState {

@available(iOS 13.0, *)
final class SwiftUIFluxTests: XCTestCase {
let store = Store<TestState>(reducer: testReducer, state: TestState(), queue: .main)
let store = Store<TestState>(reducer: testReducer, state: TestState())

func testStore() {
XCTAssert(store.state.count == 0, "Initial state is not valid")
Expand Down

0 comments on commit 0fc5d59

Please sign in to comment.