Skip to content

Commit a9d6b99

Browse files
committed
Update README
1 parent 0dc1bce commit a9d6b99

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

README.md

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
- [Atoms](#atoms)
2424
- [Modifiers](#modifiers)
2525
- [Property Wrappers](#property-wrappers)
26-
- [Contexts](#contexts)
26+
- [Context](#context)
2727
- [KeepAlive](#keepalive)
2828
- [Suspense](#suspense)
2929
- [Testing](#testing)
@@ -903,13 +903,13 @@ await context.refresh(FetchMoviesAtom())
903903
context.reset(CounterAtom())
904904
```
905905

906-
The context also provides a flexible solution for passing dynamic parameters to atom's initializer. See [Contexts](#contexts) section for more detail.
906+
The context also provides a flexible solution for passing dynamic parameters to atom's initializer. See [Context](#context) section for more detail.
907907

908908
---
909909

910-
### Contexts
910+
### Context
911911

912-
Contexts are context structure for using and interacting with the data of other atoms from a view or an another atom. The basic API common to all contexts is as follows:
912+
Context is a context structure for using and interacting with atom values from a view or an another atom.
913913

914914
|API|Use|
915915
|:--|:--|
@@ -921,7 +921,7 @@ Contexts are context structure for using and interacting with the data of other
921921
|[refresh(_:)](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomcontext/refresh(_:))|Reset an atom and await until asynchronous operation is complete.|
922922
|[reset(_:)](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomcontext/reset(_:))|Reset an atom to the default value or a first output.|
923923

924-
There are the following types context as different contextual environments, and they have some specific APIs for each.
924+
There are the following types context as different contextual environments.
925925

926926
#### [AtomViewContext](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomviewcontext)
927927

@@ -992,24 +992,23 @@ struct BooksView: View {
992992

993993
</details>
994994

995-
Context available through the `@ViewContext` property wrapper when using atoms from a view. There is no specific API for this context.
995+
Context available through the `@ViewContext` property wrapper when using atoms from a view.
996996

997997
#### [AtomTransactionContext](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomtransactioncontext)
998998

999999
<details><summary><code>📖 Click to expand example code</code></summary>
10001000

10011001
```swift
1002-
class LocationManagerDelegate: NSObject, CLLocationManagerDelegate { ... }
1003-
10041002
struct LocationManagerAtom: ValueAtom, Hashable {
1005-
func value(context: Context) -> LocationManagerProtocol {
1006-
let manager = CLLocationManager()
1007-
let delegate = LocationManagerDelegate()
1003+
final class Coordinator: NSObject, CLLocationManagerDelegate { ... }
10081004

1009-
manager.delegate = delegate
1010-
context.addTermination(manager.stopUpdatingLocation)
1011-
context.keepUntilTermination(delegate)
1005+
func makeCoordinator() -> Coordinator {
1006+
Coordinator()
1007+
}
10121008

1009+
func value(context: Context) -> LocationManagerProtocol {
1010+
let manager = CLLocationManager()
1011+
manager.delegate = context.coordinator
10131012
return manager
10141013
}
10151014
}
@@ -1024,12 +1023,12 @@ struct CoordinateAtom: ValueAtom, Hashable {
10241023

10251024
</details>
10261025

1027-
Context passed as a parameter to the primary function of each atom type.
1026+
Context passed as a parameter to the primary function of an atom type.
1027+
This context type has a `coordinator` property that preserves an instance from the time an atom is used and initialized until it is unused and cleaned up, so it can be used to cache values or as a lifecycle for an atom.
10281028

10291029
|API|Use|
10301030
|:--|:--|
1031-
|[addTermination(_:)](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomtransactioncontext/addtermination(_:))|Calls the passed closure when the atom is updated or is no longer used.|
1032-
|[keepUntilTermination(_:)](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomtransactioncontext/keepuntiltermination(_:))|Retains the given object instance until the atom is updated or is no longer used.|
1031+
|[coordinator](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomtransactioncontext/coordinator)|The atom’s associated coordinator that preservess a state until the atom will no longer be used.|
10331032

10341033
#### [AtomTestContext](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomtestcontext)
10351034

@@ -1133,7 +1132,7 @@ In order to fully test your app, this library guarantees the following principle
11331132
- Dependencies are replaceable with any of mock/stub/fake/spy per test case.
11341133
- Test cases can reproduce any possible scenarios at the view-layer.
11351134

1136-
In the test case, you first create an `AtomTestContext` instance that behaves similarly to other context types. The context allows for flexible reproduction of expected scenarios for testing using the control functions described in the [Contexts](#contexts) section.
1135+
In the test case, you first create an `AtomTestContext` instance that behaves similarly to other context types. The context allows for flexible reproduction of expected scenarios for testing using the control functions described in the [Context](#context) section.
11371136
In addition, it's able to replace the atom value with test-friendly dependencies with `override` function. It helps you to write a reproducible & stable testing.
11381137
Since atom needs to be used from the main actor to guarantee thread-safety, `XCTestCase` class that to test atoms should have `@MainActor` attribute.
11391138

Sources/Atoms/Atoms.docc/Atoms.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ SwiftUI Atom Properties offers practical capabilities to manage the complexity o
7373
- ``RefreshableAtomLoader``
7474
- ``AsyncAtomLoader``
7575
- ``ValueAtomLoader``
76+
- ``StateAtomLoader``
7677
- ``TaskAtomLoader``
7778
- ``ThrowingTaskAtomLoader``
7879
- ``AsyncSequenceAtomLoader``

0 commit comments

Comments
 (0)