-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add ability to implement custom refresh * Rename AtomUpdatedContext to AtomCurrentContext * Update docc * Rename dir name * Add test cases * Update README * Add API documentation * Fix test case
- Loading branch information
Showing
17 changed files
with
430 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
Sources/Atoms/KeepAlive.swift → Sources/Atoms/Attribute/KeepAlive.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/// An attribute protocol allows an atom to have a custom refresh ability. | ||
/// | ||
/// Note that the custom refresh ability is not triggered when the atom is overridden. | ||
/// | ||
/// ```swift | ||
/// 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) | ||
/// } | ||
/// } | ||
/// ``` | ||
/// | ||
public protocol Refreshable where Self: Atom { | ||
/// A type of the context structure that to read, set, and otherwise interacting | ||
/// 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 | ||
/// this atom is refreshed. | ||
/// | ||
/// - Parameter context: A context structure that to read, set, and otherwise interacting | ||
/// with other atoms. | ||
/// | ||
/// - Returns: A refreshed value. | ||
@MainActor | ||
func refresh(context: RefreshContext) async -> Loader.Value | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.