Skip to content

Commit

Permalink
Make Store.filter internal (#1882)
Browse files Browse the repository at this point in the history
* Make Store.filter internal

We're seeing that `@_spi` can still come up in autocomplete. Now Xcode
surfaces internal stuff too occasionally, but maybe this will suppress
it a bit.

* wip

* fix
  • Loading branch information
stephencelis committed Jan 30, 2023
1 parent 00738db commit b690a61
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Sources/ComposableArchitecture/Store.swift
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public final class Store<State, Action> {
self.scope(state: toChildState, action: { $0 })
}

@_spi(Internals) public func filter(
func filter(
_ isSent: @escaping (State, Action) -> Bool
) -> Store<State, Action> {
self.threadCheck(status: .scope)
Expand Down
28 changes: 28 additions & 0 deletions Tests/ComposableArchitectureTests/StoreFilterTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#if DEBUG
import Combine
import XCTest

@testable import ComposableArchitecture

@MainActor
final class StoreFilterTests: XCTestCase {
var cancellables: Set<AnyCancellable> = []

func testFilter() {
let store = Store<Int?, Void>(initialState: nil, reducer: EmptyReducer())
.filter { state, _ in state != nil }

let viewStore = ViewStore(store)
var count = 0
viewStore.publisher
.sink { _ in count += 1 }
.store(in: &self.cancellables)

XCTAssertEqual(count, 1)
viewStore.send(())
XCTAssertEqual(count, 1)
viewStore.send(())
XCTAssertEqual(count, 1)
}
}
#endif
17 changes: 0 additions & 17 deletions Tests/ComposableArchitectureTests/StoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -559,21 +559,4 @@ final class StoreTests: XCTestCase {

XCTAssertEqual(viewStore.state, UUID(uuidString: "deadbeef-dead-beef-dead-beefdeadbeef")!)
}

func testFilter() {
let store = Store<Int?, Void>(initialState: nil, reducer: EmptyReducer())
.filter { state, _ in state != nil }

let viewStore = ViewStore(store)
var count = 0
viewStore.publisher
.sink { _ in count += 1 }
.store(in: &self.cancellables)

XCTAssertEqual(count, 1)
viewStore.send(())
XCTAssertEqual(count, 1)
viewStore.send(())
XCTAssertEqual(count, 1)
}
}

0 comments on commit b690a61

Please sign in to comment.