Skip to content

Commit 5ddbcdd

Browse files
authored
Rename publisher-transforming scope (#314)
* Rename publisher-transforming scope * feedback
1 parent 98f9f32 commit 5ddbcdd

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

Sources/ComposableArchitecture/Internal/Deprecations.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
import Combine
22

3+
// NB: Deprecated after 0.9.0:
4+
5+
extension Store {
6+
@available(*, deprecated, renamed: "publisherScope(state:)")
7+
public func scope<P: Publisher, LocalState>(
8+
state toLocalState: @escaping (AnyPublisher<State, Never>) -> P
9+
) -> AnyPublisher<Store<LocalState, Action>, Never>
10+
where P.Output == LocalState, P.Failure == Never {
11+
self.publisherScope(state: toLocalState)
12+
}
13+
14+
@available(*, deprecated, renamed: "publisherScope(state:action:)")
15+
public func scope<P: Publisher, LocalState, LocalAction>(
16+
state toLocalState: @escaping (AnyPublisher<State, Never>) -> P,
17+
action fromLocalAction: @escaping (LocalAction) -> Action
18+
) -> AnyPublisher<Store<LocalState, LocalAction>, Never>
19+
where P.Output == LocalState, P.Failure == Never {
20+
self.publisherScope(state: toLocalState, action: fromLocalAction)
21+
}
22+
}
23+
324
// NB: Deprecated after 0.6.0:
425

526
extension Reducer {

Sources/ComposableArchitecture/Store.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public final class Store<State, Action> {
9090
/// `LocalState`.
9191
/// - fromLocalAction: A function that transforms `LocalAction` into `Action`.
9292
/// - Returns: A publisher of stores with its domain (state and action) transformed.
93-
public func scope<P: Publisher, LocalState, LocalAction>(
93+
public func publisherScope<P: Publisher, LocalState, LocalAction>(
9494
state toLocalState: @escaping (AnyPublisher<State, Never>) -> P,
9595
action fromLocalAction: @escaping (LocalAction) -> Action
9696
) -> AnyPublisher<Store<LocalState, LocalAction>, Never>
@@ -123,17 +123,18 @@ public final class Store<State, Action> {
123123
.eraseToAnyPublisher()
124124
}
125125

126+
126127
/// Scopes the store to a publisher of stores of more local state and local actions.
127128
///
128129
/// - Parameter toLocalState: A function that transforms a publisher of `State` into a publisher
129130
/// of `LocalState`.
130131
/// - Returns: A publisher of stores with its domain (state and action)
131132
/// transformed.
132-
public func scope<P: Publisher, LocalState>(
133+
public func publisherScope<P: Publisher, LocalState>(
133134
state toLocalState: @escaping (AnyPublisher<State, Never>) -> P
134135
) -> AnyPublisher<Store<LocalState, Action>, Never>
135136
where P.Output == LocalState, P.Failure == Never {
136-
self.scope(state: toLocalState, action: { $0 })
137+
self.publisherScope(state: toLocalState, action: { $0 })
137138
}
138139

139140
func send(_ action: Action) {

Sources/ComposableArchitecture/UIKit/IfLetUIKit.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ extension Store {
4545
) -> Cancellable where State == Wrapped? {
4646
let elseCancellable =
4747
self
48-
.scope(
48+
.publisherScope(
4949
state: { state in
5050
state
5151
.removeDuplicates(by: { ($0 != nil) == ($1 != nil) })
@@ -57,7 +57,7 @@ extension Store {
5757

5858
let unwrapCancellable =
5959
self
60-
.scope(
60+
.publisherScope(
6161
state: { state in
6262
state
6363
.removeDuplicates(by: { ($0 != nil) == ($1 != nil) })

Tests/ComposableArchitectureTests/StoreTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ final class StoreTests: XCTestCase {
100100
var outputs: [String] = []
101101

102102
parentStore
103-
.scope(state: { $0.map { "\($0)" }.removeDuplicates() })
103+
.publisherScope(state: { $0.map { "\($0)" }.removeDuplicates() })
104104
.sink { childStore in
105105
childStore.state
106106
.sink { outputs.append($0) }
@@ -245,7 +245,7 @@ final class StoreTests: XCTestCase {
245245
var outputs: [Int] = []
246246

247247
parentStore
248-
.scope { $0.removeDuplicates() }
248+
.publisherScope { $0.removeDuplicates() }
249249
.sink { outputs.append($0.state.value) }
250250
.store(in: &self.cancellables)
251251

0 commit comments

Comments
 (0)