-
-
Notifications
You must be signed in to change notification settings - Fork 18
Feature: Custom Resettable Attribute #98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6fdabec
Documentation: Fix subscript(_:) references
rasberik 21a13f8
Custom Resettable Attribute
rasberik 3514715
Add Resettable to README
rasberik d556036
Fix linter warnings
rasberik 0e64d89
Fix Missing _disfavoredOverload
rasberik 4bc3859
Arbitrary reset
rasberik 7b4fae4
Reflect on tests
rasberik eeddbe3
Reflect documentation
rasberik e82a113
Merge remote-tracking branch 'upstream/main' into feat/custom-resettable
rasberik 3191259
Merge upstream and sync
rasberik 4088fcf
Cleanup Dead code
rasberik 88b5eac
Format
rasberik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,36 @@ | ||
| /// An attribute protocol allows an atom to have a custom reset override. | ||
| /// | ||
| /// Note that the custom reset will be triggered even when the atom is overridden. | ||
| /// | ||
| /// ```swift | ||
| /// struct UserAtom: ValueAtom, Resettable, Hashable { | ||
| /// func value(context: Context) -> User? { | ||
| /// context.watch(FetchUserAtom()).phase.value | ||
| /// } | ||
| /// | ||
| /// func reset(context: ResetContext) { | ||
| /// context.reset(FetchUserAtom()) | ||
| /// } | ||
| /// } | ||
| /// | ||
| /// private struct FetchUserAtom: TaskAtom, Hashable { | ||
| /// func value(context: Context) async -> User? { | ||
| /// await fetchUser() | ||
| /// } | ||
| /// } | ||
| /// ``` | ||
| /// | ||
| 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) | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.