Skip to content

Commit dcecad3

Browse files
authored
Soft-deprecate Store.ifLet (pointfreeco#3382)
* Soft-deprecate `Store.ifLet` We can prefer `observe` and `if let store.scope` now. * wip * wip * Update MigratingTo1.7.md * wip
1 parent d750b2a commit dcecad3

File tree

5 files changed

+47
-12
lines changed

5 files changed

+47
-12
lines changed

.github/workflows/ci.yml

+8-8
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ jobs:
2121
matrix:
2222
command: [test, '']
2323
platform: [iOS, macOS, tvOS, watchOS, visionOS, macCatalyst]
24-
xcode: [15.2, 15.4, 16_beta_6]
25-
exclude:
24+
xcode: [15.2, 15.4, '16.0']
25+
exclude:
2626
- {xcode: 15.2, command: test}
2727
- {xcode: 15.4, command: ''}
2828
- {xcode: 15.2, platform: macCatalyst}
2929
- {xcode: 15.2, platform: tvOS}
3030
- {xcode: 15.2, platform: visionOS}
3131
- {xcode: 15.2, platform: watchOS}
32-
- {xcode: 16_beta_6, command: ''}
33-
- {xcode: 16_beta_6, platform: macCatalyst}
34-
- {xcode: 16_beta_6, platform: tvOS}
35-
- {xcode: 16_beta_6, platform: visionOS}
36-
- {xcode: 16_beta_6, platform: watchOS}
32+
- {xcode: '16.0', command: ''}
33+
- {xcode: '16.0', platform: macCatalyst}
34+
- {xcode: '16.0', platform: tvOS}
35+
- {xcode: '16.0', platform: visionOS}
36+
- {xcode: '16.0', platform: watchOS}
3737
include:
3838
- {xcode: 15.2, skip_release: 1}
3939
steps:
@@ -83,7 +83,7 @@ jobs:
8383
restore-keys: |
8484
deriveddata-examples-
8585
- name: Select Xcode 16
86-
run: sudo xcode-select -s /Applications/Xcode_16_beta_6.app
86+
run: sudo xcode-select -s /Applications/Xcode_16.0.app
8787
- name: Set IgnoreFileSystemDeviceInodeChanges flag
8888
run: defaults write com.apple.dt.XCBuild IgnoreFileSystemDeviceInodeChanges -bool YES
8989
- name: Update mtime for incremental builds

Sources/ComposableArchitecture/Documentation.docc/Articles/MigrationGuides/MigratingTo1.7.md

+31
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,8 @@ rather than going through ``Store/send(_:)``:
889889

890890
## Observing for UIKit
891891

892+
### Replacing Store.publisher
893+
892894
Prior to the observation tools one would typically subscribe to changes in the store via a Combine
893895
publisher in the entry point of a view, such as `viewDidLoad` in a `UIViewController` subclass:
894896

@@ -921,6 +923,35 @@ func viewDidLoad() {
921923
Be sure to read the documentation for ``ObjectiveC/NSObject/observe(_:)`` to learn how to best
922924
wield this tool.
923925

926+
### Replacing Store.ifLet
927+
928+
Prior to the observation tools one would typically subscribe to optional child stores via a Combine
929+
operation provided by the library:
930+
931+
```swift
932+
store
933+
.scope(state: \.child, action: \.child)
934+
.ifLet { childStore in
935+
// Use child store, _e.g._ create a child view controller
936+
} else: {
937+
// Perform clean up work, _e.g._ dismiss child view controller
938+
}
939+
.store(in: &cancellables)
940+
```
941+
942+
This can now be done more simply using the `observe` method and
943+
``Store/scope(state:action:fileID:filePath:line:column:)-2ck1n``:
944+
945+
```swift
946+
observe {
947+
if let childStore = store.scope(state: \.child, action: \.child) {
948+
// Use child store, _e.g._ create a child view controller
949+
} else {
950+
// Perform clean up work, _e.g._ dismiss child view controller
951+
}
952+
}
953+
```
954+
924955
## Incrementally migrating
925956

926957
You are most likely going to want to incrementally migrate your application to the new observation tools,

Sources/ComposableArchitecture/Documentation.docc/Extensions/Deprecations/StoreDeprecations.md

+4
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ instead.
1212
### Scoping stores
1313

1414
- ``Store/scope(state:action:)-9iai9``
15+
16+
### UIKit integration
17+
18+
- ``ifLet(then:else:)``

Sources/ComposableArchitecture/Documentation.docc/Extensions/Store.md

-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@
3535

3636
- ``StorePublisher``
3737

38-
### UIKit integration
39-
40-
- ``ifLet(then:else:)``
41-
4238
### Deprecated interfaces
4339

4440
- <doc:StoreDeprecations>

Sources/ComposableArchitecture/UIKit/IfLetUIKit.swift

+4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ extension Store {
4545
/// goes from non-`nil` to `nil`.
4646
/// - Returns: A cancellable that maintains a subscription to updates whenever the store's state
4747
/// goes from `nil` to non-`nil` and vice versa, so that the caller can react to these changes.
48+
@available(iOS, deprecated: 9999, message: "Use 'observe' and 'if let store.scope', instead.")
49+
@available(macOS, deprecated: 9999, message: "Use 'observe' and 'if let store.scope', instead.")
50+
@available(tvOS, deprecated: 9999, message: "Use 'observe' and 'if let store.scope', instead.")
51+
@available(watchOS, deprecated: 9999, message: "Use 'observe' and 'if let store.scope', instead.")
4852
public func ifLet<Wrapped>(
4953
then unwrap: @escaping (_ store: Store<Wrapped, Action>) -> Void,
5054
else: @escaping () -> Void = {}

0 commit comments

Comments
 (0)