Skip to content

Commit e121b91

Browse files
stephencelismbrandonwNFulkersonhalleepyrtsa
authored
Shared State (#2858)
* Shared State * fix compiler errors in 5.7 * fixes and tests * fix * fix * wip * longer sleeps * fix test * fix tests * Clean up some typos in SharingState.md (#2860) * public inits * wip * wip * add test for shared state and onChange * Case study for sandboxing shared state * tweaks to case study * wip * add tests to sandboxing case study * rename files * wip * simplify sync up tests * wip * fix * wip * fix $shared.publisher non-determinism and write test that currently fails but ideally would not. * more docs and a test for autoclosure * more docs * wip * update todo with persistence * wip * wip * support default `nil` optionals in `@Shared` * Introduce unavailable overload for better diagnostics * Fix autocomplete from `@Shared(.` * Revert "Fix autocomplete from `@Shared(.`" This reverts commit fd1798f. * Fix defaults * wip * Give persistence keys a synchronous update interface (#2880) * Don't use async sequence for persistence * wip * wip * wip * Update Sources/ComposableArchitecture/SharedState/PersistenceKey.swift Co-authored-by: Hal Lee <[email protected]> --------- Co-authored-by: Hal Lee <[email protected]> * Revert sharing in Todos for now * wip * wip * Pass initial shared value to strategy / register app storage (#2904) * Pass initial shared value to strategy / register app storage This PR modifies the `PersistenceKey` protocol so that its `load` and `subscribe` endpoints are handed the initial value and must return a non-optional value. By feeding this value in, we can ensure that `.appStorage` declared in a feature is registered outside the feature. * wip * wip * wip * wip * wip * wip * swift-format * Update Sources/ComposableArchitecture/Documentation.docc/Articles/SharingState.md Co-authored-by: Pyry Jahkola <[email protected]> * non-exhaustive fix * wip * remove decodable for now * Fix app storage registration with `nil` values * fix * wip * tutorial * fixes * lots of tutorial fixes * more tutorial fixes * more tutorial fixes * more tutorial fixes * tutorial fixes * wip * re-arrange test * Remove store shared preview quarantine * Add support for \.defaultInMemoryStorage (#2965) * fix * Added Privacy Manifest file (#2930) * Added Privacy Manifest file * Update [email protected] --------- Co-authored-by: Stephen Celis <[email protected]> * remove warning overloads * write default instead of register this is more consistent with SwiftUI's property wrapper, and causes less strangeness when multiple repeat properties have different defaults * move privacy manifest * wip * wip * EphemeralFileStorage -> InMemoryFileStorage * documented gotcha * add test * Shared state beta task snaps (#2976) * wip * wip * wip * wip * wip * wip * wip --------- Co-authored-by: Brandon Williams <[email protected]> * wip * Use notification center instead of KVO for user defaults observation. (#2978) * Use notification center instead of KVO for user defaults observation. * wip * wip * Introduce @SharedReader (#2979) * wip * wip * wip * wip * wip * wip * Introduce @SharedReader. * wip * wip * sendable * wip * wip --------- Co-authored-by: Stephen Celis <[email protected]> * Make Shared.Subscription.cancel public (#2983) * added failing test * Add convenience initializers * Save to file storage when app is about to be terminated (#2992) * Save file storage on termination too. * wip * Shared change tracking enhancements (#2989) * wip * wip * wip * wip * Add unavailable conformance * wip * wip * wip * Don't need to check for previews. * Add default providing persistence key (#2980) * wip - default providing key * warn on default access * Revert "warn on default access" This reverts commit 3870645. * wip * wip * wip - tests * wip - reader key * fix docs * A few changes. * A few more changes. * docs --------- Co-authored-by: Brandon Williams <[email protected]> * Fix optional shared defaults. * undo last commit but keep test * wip * Better shared state change tracking and `TestStore` interactions (#2995) * A fix for shared assertion. * fixes * wip --------- Co-authored-by: Brandon Williams <[email protected]> * docs * docs * wip * Throttle for 1 second. * fix typo in examples: `let` -> `var` (#2999) Co-authored-by: Andreas Tielmann <[email protected]> * wip * wip * fix observing projection * Ping `Shared.publisher` in `willSet` so prev/next values observable * wip * wip * remove sandbox demo * wip * wip * recover inlining * wip * wip * fix docc * wip * wip * re-entrant test * wip * Don’t assume CastableLookup (#3011) * Don’t assume CastableLookup If the observed value in `UserDefaults` is a `RawRepresentable` type, simply casting to `Value` might fail because the raw representing type could be different from `Value`. Instead of querying `UserDefaults` directly here, we should call `loadValue()` which will do the right thing for raw representable types (esp. try to call `Value.init(rawValue:)` with the value obtained from `UserDefaults`). * Add test --------- Co-authored-by: Stephen Celis <[email protected]> * 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 * sync ups clean up * more docs * more tests * shared testing tiups * wip * wip * Fix typo. (#3014) * more shared state docs * relax version of swift-dependencies. * dep change * fix == and hash on Shared and more tests * revert == changes * add test * Remove hashable conformance from shared * remove conditional encodability from shared * wip * remove syncups tutorial * wip * fix * fix file storage deletion resubscription * wip * wip * wip * wip * wip * fix * eager throttle --------- Co-authored-by: Brandon Williams <[email protected]> Co-authored-by: NF <[email protected]> Co-authored-by: Hal Lee <[email protected]> Co-authored-by: Brandon Williams <[email protected]> Co-authored-by: Pyry Jahkola <[email protected]> Co-authored-by: Daniel Lyons <[email protected]> Co-authored-by: Hilton Campbell <[email protected]> Co-authored-by: Luke Redpath <[email protected]> Co-authored-by: andtie <[email protected]> Co-authored-by: Andreas Tielmann <[email protected]> Co-authored-by: Alex Kovács <[email protected]> Co-authored-by: Zev Eisenberg <[email protected]>
1 parent 6239ed0 commit e121b91

File tree

114 files changed

+7710
-969
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+7710
-969
lines changed

Examples/CaseStudies/CaseStudies.xcodeproj/project.pbxproj

Lines changed: 127 additions & 103 deletions
Large diffs are not rendered by default.

Examples/CaseStudies/SwiftUICaseStudies/00-RootView.swift

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import SwiftUI
33

44
struct RootView: View {
55
@State var isNavigationStackCaseStudyPresented = false
6+
@State var isSignUpCaseStudyPresented = false
67

78
var body: some View {
89
NavigationStack {
@@ -33,11 +34,6 @@ struct RootView: View {
3334
OptionalBasicsView(store: store)
3435
}
3536
}
36-
NavigationLink("Shared state") {
37-
Demo(store: Store(initialState: SharedState.State()) { SharedState() }) { store in
38-
SharedStateView(store: store)
39-
}
40-
}
4137
NavigationLink("Alerts and Confirmation Dialogs") {
4238
Demo(
4339
store: Store(initialState: AlertAndConfirmationDialog.State()) {
@@ -61,6 +57,51 @@ struct RootView: View {
6157
Text("Getting started")
6258
}
6359

60+
Section {
61+
NavigationLink("In memory") {
62+
Demo(
63+
store: Store(initialState: SharedStateInMemory.State()) { SharedStateInMemory() }
64+
) { store in
65+
SharedStateInMemoryView(store: store)
66+
}
67+
}
68+
NavigationLink("User defaults") {
69+
Demo(
70+
store: Store(initialState: SharedStateUserDefaults.State()) {
71+
SharedStateUserDefaults()
72+
}
73+
) { store in
74+
SharedStateUserDefaultsView(store: store)
75+
}
76+
}
77+
NavigationLink("File storage") {
78+
Demo(
79+
store: Store(initialState: SharedStateFileStorage.State()) {
80+
SharedStateFileStorage()
81+
}
82+
) { store in
83+
SharedStateFileStorageView(store: store)
84+
}
85+
}
86+
NavigationLink("Notifications") {
87+
Demo(
88+
store: Store(initialState: SharedStateNotifications.State()) {
89+
SharedStateNotifications()
90+
}
91+
) { store in
92+
SharedStateNotificationsView(store: store)
93+
}
94+
}
95+
Button("Sign up flow") {
96+
isSignUpCaseStudyPresented = true
97+
}
98+
.sheet(isPresented: $isSignUpCaseStudyPresented) {
99+
SignUpFlow()
100+
}
101+
} header: {
102+
Text("Shared state")
103+
}
104+
64105
Section {
65106
NavigationLink("Basics") {
66107
Demo(store: Store(initialState: EffectsBasics.State()) { EffectsBasics() }) { store in
@@ -102,7 +143,7 @@ struct RootView: View {
102143

103144
Section {
104145
Button("Stack") {
105-
self.isNavigationStackCaseStudyPresented = true
146+
isNavigationStackCaseStudyPresented = true
106147
}
107148
.buttonStyle(.plain)
108149

@@ -171,7 +212,7 @@ struct RootView: View {
171212
}
172213
}
173214
.navigationTitle("Case Studies")
174-
.sheet(isPresented: self.$isNavigationStackCaseStudyPresented) {
215+
.sheet(isPresented: $isNavigationStackCaseStudyPresented) {
175216
Demo(store: Store(initialState: NavigationDemo.State()) { NavigationDemo() }) { store in
176217
NavigationDemoView(store: store)
177218
}
@@ -194,7 +235,7 @@ struct Demo<State, Action, Content: View>: View {
194235
}
195236

196237
var body: some View {
197-
self.content(self.store)
238+
content(store)
198239
}
199240
}
200241

Examples/CaseStudies/SwiftUICaseStudies/01-GettingStarted-Animations.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ struct Animations {
6565
return .run { send in
6666
for color in [Color.red, .blue, .green, .orange, .pink, .purple, .yellow, .black] {
6767
await send(.setColor(color), animation: .linear)
68-
try await self.clock.sleep(for: .seconds(1))
68+
try await clock.sleep(for: .seconds(1))
6969
}
7070
}
7171
.cancellable(id: CancelID.rainbow)

0 commit comments

Comments
 (0)