Replies: 4 comments 4 replies
-
Of course, if we introduce this in the library, we can consider other naming or error management (update func currently |
Beta Was this translation helpful? Give feedback.
-
An alternative could be to add a |
Beta Was this translation helpful? Give feedback.
-
@jegnux Generally in tests and previews you should not have to reset shared state so long as you follow this documented gotcha: https://pointfreeco.github.io/swift-composable-architecture/main/documentation/composablearchitecture/sharingstate#Previews And so your first example becomes simply: func testFeature() {
@Shared(.appStorage("count")) var count = 42
// Shared state will be 42 for all features using it.
let store = TestStore(…)
} And as such there should also be no need to call If you prefer the ergonomics of your helpers, you can totally define them in your own projects, and if so we could consider making |
Beta Was this translation helpful? Give feedback.
-
Oops, I missed last answer from Stephen, but I can close the discussion as |
Beta Was this translation helpful? Give feedback.
-
If we want to modify the value of a shared state "inline" (from a function) for test or previews, we have to go through this syntax:
And if we want to restore the default value of a
PersistenceKeyDefault
there's no real way to do it asswift-composable-architecture/Sources/ComposableArchitecture/SharedState/PersistenceKey/PersistenceKeyDefault.swift
Line 27 in 8a40e93
is internal.
I would like to introduce 3 new APIs to provide better ergonomics to Shared:
So we can write:
Or:
Or:
If the team/community doesn't think it improves the Shared api ergonomics enough to add this to the library, can we at least make
PersistenceKeyDefault.defaultValue
public, so I (or anyone) can write these extensions in my project?Beta Was this translation helpful? Give feedback.
All reactions