Skip to content

Commit f340e5f

Browse files
committed
Rename core classes
1 parent 3577f17 commit f340e5f

40 files changed

+253
-234
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ struct BooksView: View {
994994

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

997-
#### [AtomRelationContext](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomrelationcontext)
997+
#### [AtomNodeContext](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomnodecontext)
998998

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

@@ -1028,8 +1028,8 @@ Context passed as a parameter to the primary function of each atom type.
10281028

10291029
|API|Use|
10301030
|:--|:--|
1031-
|[addTermination(_:)](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomrelationcontext/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/atomrelationcontext/keepuntiltermination(_:))|Retains the given object instance until the atom is updated or is no longer used.|
1031+
|[addTermination(_:)](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomnodecontext/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/atomnodecontext/keepuntiltermination(_:))|Retains the given object instance until the atom is updated or is no longer used.|
10331033

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

Sources/Atoms/Atom/AsyncSequenceAtom.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
/// }
4545
/// ```
4646
///
47-
public protocol AsyncSequenceAtom: Atom where State == AsyncSequenceAtomValue<Sequence> {
47+
public protocol AsyncSequenceAtom: Atom where Loader == AsyncSequenceAtomLoader<Sequence> {
4848
/// The type of asynchronous sequence that this atom manages.
4949
associatedtype Sequence: AsyncSequence
5050

@@ -64,7 +64,7 @@ public protocol AsyncSequenceAtom: Atom where State == AsyncSequenceAtomValue<Se
6464

6565
public extension AsyncSequenceAtom {
6666
@MainActor
67-
var value: State {
68-
State(makeSequence: sequence)
67+
func makeLoader() -> Loader {
68+
Loader(makeSequence: sequence)
6969
}
7070
}

Sources/Atoms/Atom/Atom.swift

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ public protocol Atom {
99
/// A type representing the stable identity of this atom.
1010
associatedtype Key: Hashable
1111

12-
// TODO: Rename
13-
associatedtype State: AtomValue
12+
associatedtype Loader: AtomLoader
1413

1514
/// A type of the context structure that to read, watch, and otherwise interacting
1615
/// with other atoms.
17-
typealias Context = AtomRelationContext
16+
typealias Context = AtomNodeContext
1817

1918
/// A boolean value indicating whether the atom value should be preserved even if
2019
/// no longer watched to.
@@ -31,11 +30,8 @@ public protocol Atom {
3130
/// If this atom conforms to `Hashable`, it will adopt itself as the `key` by default.
3231
var key: Key { get }
3332

34-
/// Creates a new state that is an actual implementation of this atom.
35-
///
36-
/// - Returns: A state object that handles internal process and a value.
3733
@MainActor
38-
var value: State { get }
34+
func makeLoader() -> Loader
3935
}
4036

4137
public extension Atom {

Sources/Atoms/Atom/ModifiedAtom.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// An atom type that applies a modifier to an atom.
22
///
33
/// Use ``Atom/modifier(_:)`` instead of using this atom directly.
4-
public struct ModifiedAtom<Node: Atom, Modifier: AtomModifier>: Atom where Node.State.Value == Modifier.Value {
4+
public struct ModifiedAtom<Node: Atom, Modifier: AtomModifier>: Atom where Node.Loader.Value == Modifier.Value {
55
/// A type representing the stable identity of this atom.
66
public struct Key: Hashable {
77
private let atomKey: Node.Key
@@ -29,7 +29,7 @@ public struct ModifiedAtom<Node: Atom, Modifier: AtomModifier>: Atom where Node.
2929
Key(atomKey: atom.key, modifierKey: modifier.key)
3030
}
3131

32-
public var value: ModifiedAtomValue<Node, Modifier> {
33-
State(atom: atom, modifier: modifier)
32+
public func makeLoader() -> ModifiedAtomLoader<Node, Modifier> {
33+
Loader(atom: atom, modifier: modifier)
3434
}
3535
}

Sources/Atoms/Atom/ObservableObjectAtom.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import Combine
4848
/// }
4949
/// ```
5050
///
51-
public protocol ObservableObjectAtom: Atom where State == ObservableObjectAtomValue<ObjectType> {
51+
public protocol ObservableObjectAtom: Atom where Loader == ObservableObjectAtomLoader<ObjectType> {
5252
/// The type of observable object that this atom produces.
5353
associatedtype ObjectType: ObservableObject
5454

@@ -67,7 +67,7 @@ public protocol ObservableObjectAtom: Atom where State == ObservableObjectAtomVa
6767

6868
public extension ObservableObjectAtom {
6969
@MainActor
70-
var value: State {
71-
State(makeObject: object)
70+
func makeLoader() -> Loader {
71+
Loader(makeObject: object)
7272
}
7373
}

Sources/Atoms/Atom/PublisherAtom.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import Combine
3737
/// }
3838
/// ```
3939
///
40-
public protocol PublisherAtom: Atom where State == PublisherAtomValue<Publisher> {
40+
public protocol PublisherAtom: Atom where Loader == PublisherAtomLoader<Publisher> {
4141
/// The type of publisher that this atom manages.
4242
associatedtype Publisher: Combine.Publisher
4343

@@ -57,7 +57,7 @@ public protocol PublisherAtom: Atom where State == PublisherAtomValue<Publisher>
5757

5858
public extension PublisherAtom {
5959
@MainActor
60-
var value: State {
61-
State(makePublisher: publisher)
60+
func makeLoader() -> Loader {
61+
Loader(makePublisher: publisher)
6262
}
6363
}

Sources/Atoms/Atom/StateAtom.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
/// }
3737
/// ```
3838
///
39-
public protocol StateAtom: Atom where State == SyncAtomValue<Value> {
39+
public protocol StateAtom: Atom where Loader == ValueAtomLoader<Value> {
4040
/// The type of state value that this atom produces.
4141
associatedtype Value
4242

@@ -77,8 +77,8 @@ public protocol StateAtom: Atom where State == SyncAtomValue<Value> {
7777

7878
public extension StateAtom {
7979
@MainActor
80-
var value: State {
81-
State(getValue: defaultValue)
80+
func makeLoader() -> Loader {
81+
Loader(getValue: defaultValue)
8282
}
8383

8484
@MainActor

Sources/Atoms/Atom/TaskAtom.swift

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
/// }
3535
/// ```
3636
///
37-
public protocol TaskAtom: Atom where State == AsyncAtomValue<Value, Never> {
37+
public protocol TaskAtom: Atom where Loader == TaskAtomLoader<Value> {
3838
/// The type of value that this atom produces.
3939
associatedtype Value
4040

@@ -53,11 +53,7 @@ public protocol TaskAtom: Atom where State == AsyncAtomValue<Value, Never> {
5353

5454
public extension TaskAtom {
5555
@MainActor
56-
var value: State {
57-
State { context in
58-
Task {
59-
await context.withAtomContext(value)
60-
}
61-
}
56+
func makeLoader() -> Loader {
57+
Loader(getValue: value)
6258
}
6359
}

Sources/Atoms/Atom/ThrowingTaskAtom.swift

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
/// }
3737
/// ```
3838
///
39-
public protocol ThrowingTaskAtom: Atom where State == AsyncAtomValue<Value, Error> {
39+
public protocol ThrowingTaskAtom: Atom where Loader == ThrowingTaskAtomLoader<Value> {
4040
/// The type of value that this atom produces.
4141
associatedtype Value
4242

@@ -57,11 +57,7 @@ public protocol ThrowingTaskAtom: Atom where State == AsyncAtomValue<Value, Erro
5757

5858
public extension ThrowingTaskAtom {
5959
@MainActor
60-
var value: State {
61-
State { context in
62-
Task {
63-
try await context.withAtomContext(value)
64-
}
65-
}
60+
func makeLoader() -> Loader {
61+
Loader(getValue: value)
6662
}
6763
}

Sources/Atoms/Atom/ValueAtom.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
/// }
3030
/// ```
3131
///
32-
public protocol ValueAtom: Atom where State == SyncAtomValue<Value> {
32+
public protocol ValueAtom: Atom where Loader == ValueAtomLoader<Value> {
3333
/// The type of value that this atom produces.
3434
associatedtype Value
3535

@@ -48,7 +48,7 @@ public protocol ValueAtom: Atom where State == SyncAtomValue<Value> {
4848

4949
public extension ValueAtom {
5050
@MainActor
51-
var value: State {
52-
State(getValue: value)
51+
func makeLoader() -> Loader {
52+
Loader(getValue: value)
5353
}
5454
}

0 commit comments

Comments
 (0)