You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+30-39Lines changed: 30 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,12 +20,12 @@
20
20
-[Basic Tutorial](#basic-tutorial)
21
21
-[Guides](#guides)
22
22
-[AtomRoot](#atomroot)
23
-
-[Atoms](#atoms-1)
24
-
-[Modifiers](#modifiers)
25
-
-[Attributes](#attributes)
26
-
-[Property Wrappers](#property-wrappers)
23
+
-[Atom](#atom)
24
+
-[Modifier](#modifier)
25
+
-[Attribute](#attribute)
26
+
-[Property Wrapper](#property-wrapper)
27
27
-[Context](#context)
28
-
-[Views](#views)
28
+
-[View](#view)
29
29
-[Techniques](#techniques)
30
30
-[Advanced Usage](#advanced-usage)
31
31
-[Dealing with Known SwiftUI Bugs](#dealing-with-known-swiftui-bugs)
@@ -365,7 +365,7 @@ struct ExampleApp: App {
365
365
366
366
---
367
367
368
-
### Atoms
368
+
### Atom
369
369
370
370
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.
371
371
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.*
@@ -630,7 +630,7 @@ struct ContactView: View {
630
630
631
631
---
632
632
633
-
### Modifiers
633
+
### Modifier
634
634
635
635
Modifiers can be applied to an atom to produce a different versions of the original atom to make it more coding friendly or to reduce view re-computation for performance optimization.
The following property wrappers are used to bind atoms to view and recompute the view with data changes.
862
862
By retrieving the atom through these property wrappers, the internal system marks the atom as in-use and the values are cached until that view is dismantled.
@@ -1022,24 +1022,23 @@ Context is a structure for using and interacting with atom values from views or
1022
1022
1023
1023
|API|Use|
1024
1024
|:--|:--|
1025
-
|[watch](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomwatchablecontext/watch(_:))|Obtains an atom value and starts watching its update.|
1026
-
|[read](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomcontext/read(_:))|Obtains an atom value but does not watch its update.|
1027
-
|[set](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomcontext/set(_:for:))|Sets a new value to the atom.|
1028
-
|[modify](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomcontext/modify(_:body:))|Modifies the cached atom value.|
1025
+
|[watch(_:)](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomtestcontext/watch(_:))|Gets an atom value and starts watching its update.|
1026
+
|[read(_:)](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomcontext/read(_:))|Gets an atom value but does not watch its update.|
1027
+
|[set(_:for:)](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomcontext/set(_:for:))|Sets a new value to the atom.|
1028
+
|[modify(_:body:)](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomcontext/modify(_:body:))|Modifies the cached atom value.|
1029
1029
|[subscript[]](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomcontext/subscript(_:))|Read-write access for applying mutating methods.|
1030
-
|[refresh](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomcontext/refresh(_:)-1gb3a)|Produce a new value of the atom after waiting until asynchronous operation is complete.|
1031
-
|[reset](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomcontext/reset(_:))|Reset an atom to the default value or a first output.|
1030
+
|[refresh(_:)](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomcontext/refresh(_:)-1gb3a)|Produce a new value of the atom after waiting until asynchronous operation is complete.|
1031
+
|[reset(_:)](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomcontext/reset(_:))|Reset an atom to the default value or a first output.|
1032
1032
1033
-
There are the following types context as different contextual environments.
1034
-
The APIs described in each section below are their own specific functionality depending on the environment in which it is used, in addition to the above common APIs.
1033
+
Contexts are provided in the following types depending on the environment where they are provided. In addition to the common APIs described above, each context type may have its unique functionalities.
A context available through the `@ViewContext` property wrapper when using atoms from a view.
1039
1038
1040
1039
|API|Use|
1041
1040
|:--|:--|
1042
-
|[binding](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomviewcontext/binding(_:))|Gets a binding to the atom state.|
1041
+
|[binding(_:)](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomviewcontext/binding(_:))|Gets a binding to the atom state.|
1043
1042
|[snapshot()](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomviewcontext/snapshot())|For debugging, takes a snapshot that captures specific set of values of atoms.|
A context passed as a parameter to the primary function of each atom type.
1120
-
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.
1121
-
1122
-
|API|Use|
1123
-
|:--|:--|
1124
-
|[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.|
let manager = context.watch(LocationManagerAtom())
1146
-
return manager.location?.coordinate
1147
-
}
1148
-
}
1149
1139
```
1150
1140
1151
1141
</details>
@@ -1156,6 +1146,7 @@ A context that can simulate any scenarios in which atoms are used from a view or
1156
1146
1157
1147
|API|Use|
1158
1148
|:--|:--|
1149
+
|[lookup(_:)](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomtestcontext/lookup(_:))|Gets an atom value without creating a cache.|
1159
1150
|[unwatch(_:)](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomtestcontext/unwatch(_:))|Simulates a scenario in which the atom is no longer watched.|
1160
1151
|[override(_:with:)](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomtestcontext/override(_:with:)-40pb3)|Overwrites the output of a specific atom or all atoms of the given type with the fixed value.|
1161
1152
|[waitForUpdate(timeout:)](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomtestcontext/waitforupdate(timeout:))|Waits until any of the atoms watched through this context have been updated.|
@@ -1205,7 +1196,7 @@ class FetchMusicsTests: XCTestCase {
This library is designed with the shared state as a single source of truth first principle, but also the state can be scoped depending on the intended use.
1255
1246
Scoped atoms preserves the atom state in the [AtomScope](#atomscope) nearest to the ancestor of where it is used and prevents it from being shared out of scope. `Scoped` is the attribute for that feature.
This is also useful when multiple identical screens are stacked and each screen needs isolated states such as user inputs.
1308
1299
Note that other atoms that depend on scoped atoms will be in a shared state and must be given `Scoped` attribute as well in order to scope them as well.
1309
1300
1310
-
#### Atom Effects
1301
+
#### Atom Effect
1311
1302
1312
1303
Atom effects are an API for managing side effects that are synchronized with the atom's lifecycle. They are widely applicable for variety of usage such as state synchronization, state persistence, logging, and etc, by observing and reacting to state changes.
1313
1304
@@ -1370,7 +1361,7 @@ final class CountTimerEffect: AtomEffect {
1370
1361
}
1371
1362
```
1372
1363
1373
-
#### Override Atoms
1364
+
#### Atom Override
1374
1365
1375
1366
You can override atoms in [AtomRoot](#atomroot) or [AtomScope](#atomscope) to overwirete the atom states for dependency injection or faking state in particular view, which is useful especially for testing.
0 commit comments