Skip to content

Commit 5d1d382

Browse files
committed
ViewStore producer API improvements
- `StoreProducer<State>` renamed to `Produced<Value>` - `viewStore.producer: StoreProducer<State>` renamed to `viewStore.produced: Produced<State>`
1 parent efd8f43 commit 5d1d382

File tree

5 files changed

+21
-15
lines changed

5 files changed

+21
-15
lines changed

Sources/ComposableArchitecture/Debugging/ReducerInstrumentation.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import ReactiveSwift
21
import os.signpost
32

43
extension Reducer {

Sources/ComposableArchitecture/Store.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,20 +195,22 @@ public final class Store<State, Action> {
195195

196196
/// A producer of store state.
197197
@dynamicMemberLookup
198-
public struct StoreProducer<State>: SignalProducerConvertible {
199-
public let producer: Effect<State, Never>
198+
public struct Produced<Value>: SignalProducerConvertible {
199+
public let producer: Effect<Value, Never>
200200

201-
init(_ upstream: Effect<State, Never>) {
201+
init(by upstream: Effect<Value, Never>) {
202202
self.producer = upstream
203203
}
204204

205205
/// Returns the resulting producer of a given key path.
206-
public subscript<LocalState>(
207-
dynamicMember keyPath: KeyPath<State, LocalState>
208-
) -> Effect<LocalState, Never>
209-
where LocalState: Equatable {
206+
public subscript<LocalValue>(
207+
dynamicMember keyPath: KeyPath<Value, LocalValue>
208+
) -> Effect<LocalValue, Never> where LocalValue: Equatable {
210209
self.producer.map(keyPath).skipRepeats()
211210
}
212-
213-
public var state: Effect<State, Never> { producer }
214211
}
212+
213+
@available(*, deprecated, message:"""
214+
Consider using `Produced<State>` instead, this typealias is added for backward compatibility and will be removed in the next major release.
215+
""")
216+
public typealias StoreProducer<State> = Produced<State>

Sources/ComposableArchitecture/ViewStore.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ import SwiftUI
4444
@dynamicMemberLookup
4545
public final class ViewStore<State, Action>: ObservableObject {
4646
/// A producer of state.
47-
public let producer: StoreProducer<State>
47+
public let produced: Produced<State>
48+
49+
@available(*, deprecated, message: """
50+
Consider using `.produced` instead, this variable is added for backward compatibility and will be removed in the next major release.
51+
""")
52+
var producer: Produced<State> { produced }
4853

4954
/// Initializes a view store from a store.
5055
///
@@ -57,7 +62,7 @@ public final class ViewStore<State, Action>: ObservableObject {
5762
removeDuplicates isDuplicate: @escaping (State, State) -> Bool
5863
) {
5964
let producer = store.$state.producer.skipRepeats(isDuplicate)
60-
self.producer = StoreProducer(producer)
65+
self.produced = Produced(by: producer)
6166
self.state = store.state
6267
self._send = store.send
6368
producer.startWithValues { [weak self] in

Tests/ComposableArchitectureTests/MemoryManagementTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ final class MemoryManagementTests: XCTestCase {
1414
let viewStore = ViewStore(store)
1515

1616
var count = 0
17-
viewStore.producer.producer.startWithValues { count = $0 }
17+
viewStore.produced.producer.startWithValues { count = $0 }
1818

1919
XCTAssertEqual(count, 0)
2020
viewStore.send(())
@@ -29,7 +29,7 @@ final class MemoryManagementTests: XCTestCase {
2929
let viewStore = ViewStore(Store(initialState: 0, reducer: counterReducer, environment: ()))
3030

3131
var count = 0
32-
viewStore.producer.producer.startWithValues { count = $0 }
32+
viewStore.produced.producer.startWithValues { count = $0 }
3333

3434
XCTAssertEqual(count, 0)
3535
viewStore.send(())

Tests/ComposableArchitectureTests/StoreTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ final class StoreTests: XCTestCase {
284284
let vs = ViewStore(childStore)
285285

286286
vs
287-
.producer.producer
287+
.produced.producer
288288
.startWithValues { _ in }
289289

290290
vs.send(false)

0 commit comments

Comments
 (0)