Skip to content

Commit 1c388f4

Browse files
authored
Make FileStorage more opaque (#3010)
* Make `FileStorage` more opaque Previously, we had a public protocol and conformances, but we don't expect anyone to conform outside the library, so instead let's hide things in a more opaque struct. The downside of this PR is that it's a breaking API change pretty late in the game: ```diff -$0.defaultFileStorage = InMemoryFileStorage() +$0.defaultFileStorage = .inMemory ``` We could add public deprecated functions that emulate the old initializers if we think it's worth it... * wip * wip * wip * wip * wip * wip * fix for 5.7.1
1 parent 03d4037 commit 1c388f4

File tree

9 files changed

+279
-297
lines changed

9 files changed

+279
-297
lines changed

Examples/SyncUps/SyncUps/App.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ struct SyncUpsApp: App {
99
._printChanges()
1010
} withDependencies: {
1111
if ProcessInfo.processInfo.environment["UITesting"] == "true" {
12-
$0.defaultFileStorage = InMemoryFileStorage()
12+
$0.defaultFileStorage = .inMemory
1313
}
1414
}
1515

Examples/SyncUps/SyncUpsTests/AppFeatureTests.swift

+6-11
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@ final class AppFeatureTests: XCTestCase {
77
@MainActor
88
func testDetailEdit() async throws {
99
var syncUp = SyncUp.mock
10-
11-
let store = TestStore(
12-
initialState: AppFeature.State(syncUpsList: SyncUpsList.State(syncUps: [syncUp]))
13-
) {
10+
@Shared(.syncUps) var syncUps = [syncUp]
11+
let store = TestStore(initialState: AppFeature.State()) {
1412
AppFeature()
1513
}
1614

17-
let sharedSyncUp = try XCTUnwrap(store.state.syncUpsList.$syncUps[id: syncUp.id])
15+
let sharedSyncUp = try XCTUnwrap($syncUps[id: syncUp.id])
1816

1917
await store.send(\.path.push, (id: 0, .detail(SyncUpDetail.State(syncUp: sharedSyncUp)))) {
2018
$0.path[id: 0] = .detail(SyncUpDetail.State(syncUp: sharedSyncUp))
@@ -41,15 +39,12 @@ final class AppFeatureTests: XCTestCase {
4139
@MainActor
4240
func testDelete() async throws {
4341
let syncUp = SyncUp.mock
44-
45-
let store = TestStore(
46-
initialState: AppFeature.State(syncUpsList: SyncUpsList.State(syncUps: [syncUp]))
47-
) {
42+
@Shared(.syncUps) var syncUps = [syncUp]
43+
let store = TestStore(initialState: AppFeature.State()) {
4844
AppFeature()
4945
}
5046

51-
guard let sharedSyncUp = store.state.syncUpsList.$syncUps[id: syncUp.id]
52-
else { return }
47+
let sharedSyncUp = try XCTUnwrap($syncUps[id: syncUp.id])
5348

5449
await store.send(\.path.push, (id: 0, .detail(SyncUpDetail.State(syncUp: sharedSyncUp)))) {
5550
$0.path[id: 0] = .detail(SyncUpDetail.State(syncUp: Shared(syncUp)))

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

+1
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@
2727
### Key-path access
2828

2929
- ``PersistenceReaderKey/appStorage(_:)-5jsie``
30+
- ``AppStorageKeyPathKey``

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

+4
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@
55
### Storing a value
66

77
- ``PersistenceReaderKey/fileStorage(_:)``
8+
9+
### Overriding storage
10+
11+
- ``FileStorage``

Sources/ComposableArchitecture/Internal/Deprecations.swift

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
// NB: Deprecated with 1.10.0:
2+
3+
@available(*, deprecated, message: "Use '.fileSystem' ('FileStorage.fileSystem') instead")
4+
public func LiveFileStorage() -> FileStorage { .fileSystem }
5+
6+
@available(*, deprecated, message: "Use '.inMemory' ('FileStorage.inMemory') instead")
7+
public func InMemoryFileStorage() -> FileStorage { .inMemory }
8+
9+
// NB: Deprecated with 1.0.0:
10+
111
@available(*, unavailable, renamed: "Effect")
212
public typealias EffectTask = Effect
313

0 commit comments

Comments
 (0)