Surface persistence strategy of a Shared property #2982
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This branch introduces a second generic to
Shared
that tracks the underlying persistence strategy:This means that a particular persistence strategy can expose endpoints that the
Shared
could statically call. For example, a remotely-backedShared
could expose arefresh
endpoint for fetching the latest data:Now this change comes with some complications and source incompatibilities with earlier periods in the beta. In particular,
Shared
properties that are not backed by a persistence key can no longer be specified simply:Due to limitations in Swift (lack of default generics, for example), the new generic cannot be inferred in this situation. The type used to describe the persistence strategy of such a shared value is
Any
, and so there is a type alias to simplify:In the future, if Swift ever does get default generics, we could maybe get rid of these type aliases.
We'd love it if folks could take this change for a spin and/or provide feedback. We're trying to strike the right balance for shared state in terms of features and power without sacrificing too much in the way of usability and API surface area.