0.5.0
New features
- Modified atoms such as
TaskAtom
s modified with.phase
modifier now supports to refresh.
struct FetchMoviesTaskAtom: ThrowingTaskAtom, Hashable {
func value(context: Context) async throws -> [Movies] {
try await fetchMovies()
}
}
sturct MoviesView: View {
@ViewContext
var context
var body: some View {
...
.refreshable {
await context.refresh(FetchMoviesTaskAtom().phase)
}
}
}
- Added
Refreshable
attribute that allows you to implement a custom refresh ability to an atom.
struct RandomIntAtom: ValueAtom, Refreshable, Hashable {
func value(context: Context) -> Int {
0
}
func refresh(context: RefreshContext) async -> Int {
try? await Task.sleep(nanoseconds: 3 * 1_000_000_000)
return .random(in: 0..<100)
}
}
sturct RandomIntView: View {
@ViewContext
var context
var body: some View {
...
.refreshable {
await context.refresh(RandomIntAtom())
}
}
}
What's Changed
- Minor refactoring by @ra1028 in #88
- Add ability to refresh modified atoms by @ra1028 in #91
- Custom Refreshable Attribute by @ra1028 in #92
Full Changelog: 0.4.2...0.5.0