Skip to content

Commit d61186f

Browse files
committed
Add documentation for TransactionModifier
1 parent 72d312b commit d61186f

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

Sources/OpenSwiftUICore/Data/Transaction/TransactionModifier.swift

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,17 @@ package import OpenGraphShims
1010

1111
// MARK: - TransactionModifier
1212

13+
/// Modifier to set a transaction adjustment.
1314
@frozen
1415
public struct _TransactionModifier: ViewModifier, _GraphInputsModifier, PrimitiveViewModifier {
16+
/// A closure that transforms the current transaction.
17+
///
18+
/// This closure receives the current transaction and can modify it in place.
1519
public var transform: (inout Transaction) -> ()
1620

21+
/// Creates a transaction modifier with the specified transform closure.
22+
///
23+
/// - Parameter transform: A closure that modifies the transaction in place.
1724
public init(transform: @escaping (inout Transaction) -> ()) {
1825
self.transform = transform
1926
}
@@ -42,12 +49,25 @@ private struct ChildTransaction: Rule, AsyncAttribute {
4249

4350
// MARK: - ValueTransactionModifier
4451

52+
/// Modifier to set a transaction adjustment with a value constraint.
4553
@frozen
4654
public struct _ValueTransactionModifier<Value>: ViewModifier, _GraphInputsModifier, PrimitiveViewModifier where Value: Equatable {
55+
/// The value to monitor for changes.
56+
///
57+
/// When this value changes (as determined by `Equatable` conformance),
58+
/// the transaction modifier will be applied.
4759
public var value: Value
4860

61+
/// A closure that transforms the current transaction.
62+
///
63+
/// This closure receives the current transaction and can modify it in place.
4964
public var transform: (inout Transaction) -> ()
5065

66+
/// Creates a value transaction modifier with the specified value and transform closure.
67+
///
68+
/// - Parameters:
69+
/// - value: The value to monitor for changes.
70+
/// - transform: A closure that modifies the transaction in place.
5171
public init(value: Value, transform: @escaping (inout Transaction) -> Void) {
5272
self.value = value
5373
self.transform = transform
@@ -76,6 +96,10 @@ public struct _ValueTransactionModifier<Value>: ViewModifier, _GraphInputsModifi
7696
@available(*, unavailable)
7797
extension _ValueTransactionModifier: Sendable {}
7898

99+
/// A stateful rule that tracks value changes to determine when to update transactions.
100+
///
101+
/// This structure maintains state about a value being monitored, comparing new values
102+
/// with the previous ones to detect changes.
79103
struct ValueTransactionSeed<V>: StatefulRule, AsyncAttribute where V: Equatable {
80104
var _value: Attribute<V>
81105
var _transactionSeed: Attribute<UInt32>
@@ -123,13 +147,19 @@ private struct ChildValueTransaction: Rule, AsyncAttribute {
123147
}
124148

125149
// MARK: - PushPopTransactionModifier
126-
127150
@frozen
128151
public struct _PushPopTransactionModifier<Content>: ViewModifier, MultiViewModifier, PrimitiveViewModifier where Content: ViewModifier {
152+
/// The content to which the transaction modification applies.
129153
public var content: Content
130154

155+
/// The base transaction modifier to apply.
131156
public var base: _TransactionModifier
132157

158+
/// Creates a push-pop transaction modifier with the specified content and transform closure.
159+
///
160+
/// - Parameters:
161+
/// - content: The content to which the transaction modification applies.
162+
/// - transform: A closure that modifies the transaction in place.
133163
public init(content: Content, transform: @escaping (inout Transaction) -> Void) {
134164
self.content = content
135165
self.base = .init(transform: transform)
@@ -164,21 +194,35 @@ extension _PushPopTransactionModifier: Sendable {}
164194

165195
extension _GraphInputs {
166196
private struct SavedTransactionKey: ViewInput {
197+
/// The default value for saved transactions.
167198
static let defaultValue: [Attribute<Transaction>] = []
168199
}
169200

201+
/// The stack of saved transactions.
202+
///
203+
/// This property maintains a stack of transaction contexts that can be restored
204+
/// after temporary modifications.
170205
package var savedTransactions: [Attribute<Transaction>] {
171206
get { self[SavedTransactionKey.self] }
172207
set { self[SavedTransactionKey.self] = newValue }
173208
}
174209
}
175210

176211
extension _ViewInputs {
212+
/// The stack of saved transactions.
213+
///
214+
/// This property provides access to the transaction stack from view inputs.
177215
package var savedTransactions: [Attribute<Transaction>] {
178216
get { base.savedTransactions }
179217
set { base.savedTransactions = newValue }
180218
}
181219

220+
/// Gets the transaction to use for geometry calculations.
221+
///
222+
/// This method returns the first saved transaction if available, or the current
223+
/// transaction otherwise.
224+
///
225+
/// - Returns: The transaction attribute to use for geometry calculations.
182226
package func geometryTransaction() -> Attribute<Transaction> {
183227
savedTransactions.first ?? transaction
184228
}

0 commit comments

Comments
 (0)