Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ struct FetchMoviesPhaseAtom: ValueAtom, Refreshable, Hashable {
context.watch(FetchMoviesTaskAtom().phase)
}

func refresh(context: RefreshContext) async -> AsyncPhase<[Movies], Error> {
func refresh(context: CurrentContext) async -> AsyncPhase<[Movies], Error> {
await context.refresh(FetchMoviesTaskAtom().phase)
}

Expand Down Expand Up @@ -838,7 +838,7 @@ struct RandomIntAtom: ValueAtom, Resettable, Hashable {
return .random(in: 0..<100, using: &generator)
}

func reset(context: ResetContext) {
func reset(context: CurrentContext) {
context.reset(RandomNumberGeneratorAtom())
}
}
Expand Down
4 changes: 4 additions & 0 deletions Sources/Atoms/Atom/Atom.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public protocol Atom {
/// with other atoms.
typealias Context = AtomTransactionContext<Coordinator>

/// A type of the context structure to read, set, and otherwise interact
/// with other atoms.
typealias CurrentContext = AtomCurrentContext<Loader.Coordinator>

/// A type of the context structure to read, set, and otherwise interact
/// with other atoms.
typealias UpdatedContext = AtomCurrentContext<Loader.Coordinator>
Expand Down
8 changes: 2 additions & 6 deletions Sources/Atoms/Attribute/Refreshable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/// context.watch(FetchUserAtom().phase)
/// }
///
/// func refresh(context: RefreshContext) async -> AsyncPhase<User?, Never> {
/// func refresh(context: CurrentContext) async -> AsyncPhase<User?, Never> {
/// await context.refresh(FetchUserAtom().phase)
/// }
/// }
Expand All @@ -22,10 +22,6 @@
/// ```
///
public protocol Refreshable where Self: Atom {
/// A type of the context structure to read, set, and otherwise interact
/// with other atoms.
typealias RefreshContext = AtomCurrentContext<Loader.Coordinator>

/// Refreshes and then return a result value.
///
/// The value returned by this method will be cached as a new value when
Expand All @@ -36,5 +32,5 @@ public protocol Refreshable where Self: Atom {
///
/// - Returns: A refreshed value.
@MainActor
func refresh(context: RefreshContext) async -> Loader.Value
func refresh(context: CurrentContext) async -> Loader.Value
}
8 changes: 2 additions & 6 deletions Sources/Atoms/Attribute/Resettable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/// context.watch(FetchUserAtom().phase)
/// }
///
/// func reset(context: ResetContext) {
/// func reset(context: CurrentContext) {
/// context.reset(FetchUserAtom())
/// }
/// }
Expand All @@ -22,16 +22,12 @@
/// ```
///
public protocol Resettable where Self: Atom {
/// A type of the context structure to read, set, and otherwise interact
/// with other atoms.
typealias ResetContext = AtomCurrentContext<Loader.Coordinator>

/// Arbitrary reset method to be executed on atom reset.
///
/// This is arbitrary custom reset method that replaces regular atom reset functionality.
///
/// - Parameter context: A context structure to read, set, and otherwise interact
/// with other atoms.
@MainActor
func reset(context: ResetContext)
func reset(context: CurrentContext)
}
10 changes: 10 additions & 0 deletions Sources/Atoms/Deprecated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ public extension Atom {
}
}

public extension Resettable {
@available(*, deprecated, renamed: "CurrentContext")
typealias ResetContext = AtomCurrentContext<Loader.Coordinator>
}

public extension Refreshable {
@available(*, deprecated, renamed: "CurrentContext")
typealias RefreshContext = AtomCurrentContext<Loader.Coordinator>
}

public extension AtomScope {
@available(*, deprecated, renamed: "init(inheriting:content:)")
init(
Expand Down
6 changes: 3 additions & 3 deletions Tests/AtomsTests/Utilities/TestAtom.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ struct TestCustomRefreshableAtom<Publisher: Combine.Publisher>: PublisherAtom, R
makePublisher()
}

func refresh(context: RefreshContext) async -> AsyncPhase<Publisher.Output, Publisher.Failure> {
func refresh(context: CurrentContext) async -> AsyncPhase<Publisher.Output, Publisher.Failure> {
refresh()
}
}

struct TestCustomResettableAtom<T>: StateAtom, Resettable {
var defaultValue: (Context) -> T
var reset: (ResetContext) -> Void
var reset: (CurrentContext) -> Void

var key: UniqueKey {
UniqueKey()
Expand All @@ -105,7 +105,7 @@ struct TestCustomResettableAtom<T>: StateAtom, Resettable {
defaultValue(context)
}

func reset(context: ResetContext) {
func reset(context: CurrentContext) {
reset(context)
}
}
Expand Down