Skip to content

0.5.0

Compare
Choose a tag to compare
@ra1028 ra1028 released this 26 Dec 11:15
· 57 commits to main since this release
24bab62

New features

  • Modified atoms such as TaskAtoms 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

Full Changelog: 0.4.2...0.5.0