Skip to content

Commit c368a51

Browse files
committed
Update documentation
1 parent 95734e7 commit c368a51

File tree

4 files changed

+32
-19
lines changed

4 files changed

+32
-19
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ To look into the APIs in more detail, visit the [API referrence](https://ra1028.
377377

378378
### [AtomRoot](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomroot)
379379

380-
Provides the internal store which provides atoms to view-tree through environment values.
380+
Provides a store object which manages the state of atoms to view-tree through environment values.
381381
It must be the root of any views to manage atoms used throughout the application.
382382

383383
```swift
@@ -398,7 +398,7 @@ struct ExampleApp: App {
398398
### Atoms
399399

400400
An atom represents a piece of state and is the source of truth for your app. It can also represent a derived data by combining and transforming one or more other atoms.
401-
Each atom does not actually have a global data inside, and retrieve values from the internal store provided by the `AtomRoot`. That's why *they can be accessed from anywhere, but never lose testability.*
401+
Each atom does not actually have a global data inside, and retrieve values from the store provided by the `AtomRoot`. That's why *they can be accessed from anywhere, but never lose testability.*
402402

403403
An atom and its value are associated using a unique `key` which is automatically defined if the atom conforms to `Hashable`, but you can also define it explicitly without Hashable.
404404

@@ -1458,7 +1458,7 @@ struct RootView: View {
14581458
</details>
14591459

14601460
Unfortunately, SwiftUI has a bug in iOS14 or lower where the `EnvironmentValue` is removed from a screen presented with `.sheet` just before dismissing it. Since this library is designed based on `EnvironmentValue`, this bug end up triggering the friendly `assertionFailure` that is added so that developers can easily aware of forgotten `AtomRoot` implementation.
1461-
As a workaround, `AtomScope` has the ability to explicitly inherit the internal store through `AtomViewContext` from the parent view.
1461+
As a workaround, `AtomScope` has the ability to explicitly inherit the store through `AtomViewContext` from the parent view.
14621462

14631463
#### Some SwiftUI modifiers cause memory leak (Fixed in iOS16)
14641464

Sources/Atoms/AtomRoot.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import SwiftUI
22

3-
/// A view that stores the state container of atoms and provides an internal store to view-tree
4-
/// through environment values.
3+
/// A view that stores the state of atoms.
54
///
65
/// It must be the root of any views to manage the state of atoms used throughout the application.
76
///

Sources/Atoms/AtomScope.swift

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,23 @@ import SwiftUI
22

33
/// A view to override or monitor atoms in scope.
44
///
5-
/// For some reasons, sometimes SwiftUI can fail to pass environment values in the view-tree.
6-
/// The typical example is that, if you use SwiftUI view inside UIKit view, it could fail as
7-
/// SwiftUI can't pass environment values across UIKit.
5+
/// This view allows you to monitor changes of atoms used in descendant views by``AtomScope/observe(_:)``.
6+
///
7+
/// ```swift
8+
/// AtomScope {
9+
/// MyView()
10+
/// }
11+
/// .observe { snapshot in
12+
/// if let count = snapshot.lookup(CounterAtom()) {
13+
/// print(count)
14+
/// }
15+
/// }
16+
/// ```
17+
///
18+
/// It inherits from the atom store provided by ``AtomRoot`` through environment values by default,
19+
/// but sometimes SwiftUI can fail to pass environment values in the view-tree for some reason.
20+
/// The typical example is that, in case you use SwiftUI view inside UIKit view, it could fail as
21+
/// SwiftUI can't pass environment values to UIKit across boundaries.
822
/// In that case, you can wrap the view with ``AtomScope`` and pass a view context to it so that
923
/// the descendant views can explicitly inherit the store.
1024
///
@@ -21,19 +35,19 @@ import SwiftUI
2135
/// }
2236
/// ```
2337
///
24-
/// ``AtomScope`` can be created without passing a view context, and in this case, it inherits
25-
/// from an internal store through environment values from ``AtomRoot.
26-
/// It allows you to monitor changes of atoms used in descendant views by``AtomScope/observe(_:)``.
38+
/// Additionally, if for some reason your app cannot use ``AtomRoot`` to manage the store
39+
/// that manages the state of atoms, you can manage the store on your own and pass the instance
40+
/// to ``AtomScope`` so that you can use the atoms in descendant views.
2741
///
2842
/// ```swift
29-
/// AtomScope {
30-
/// MyView()
31-
/// }
32-
/// .observe { snapshot in
33-
/// if let count = snapshot.lookup(CounterAtom()) {
34-
/// print(count)
35-
/// }
43+
/// let store = AtomStore()
44+
/// let rootView = AtomScope(store) {
45+
/// RootView()
3646
/// }
47+
/// let window = UIWindow(frame: UIScreen.main.bounds)
48+
///
49+
/// window.rootViewController = UIHostingController(rootView: rootView)
50+
/// window.makeKeyAndVisible()
3751
/// ```
3852
///
3953
public struct AtomScope<Content: View>: View {

Sources/Atoms/Context/AtomTestContext.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Foundation
33

44
/// A context structure that to read, watch, and otherwise interacting with atoms in testing.
55
///
6-
/// This context has an internal Store that manages atoms, so it can be used to test individual
6+
/// This context has a store that manages the state of atoms, so it can be used to test individual
77
/// atoms or their interactions with other atoms without depending on the SwiftUI view tree.
88
/// Furthermore, unlike other contexts, it is possible to override or observe changes in atoms
99
/// by this itself.

0 commit comments

Comments
 (0)