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
OpenAttributeGraph is an open source implementation of Apple's Private framework - AttributeGraph
9
+
OpenAttributeGraph is an open source implementation of Apple's Private framework - AttributeGraph which is a high performance computing engine written in C++ and Swift.
10
10
11
-
AttributeGraph is a high performance computing engine written in C++ and Swift.
12
-
13
-
And it powers the underlying computing and diffing of SwiftUI.
11
+
And it powers the underlying computing and diffing of [OpenSwiftUI](https://github.com/OpenSwiftUIProject/OpenSwiftUI).
14
12
15
13
|**CI Status**|
16
14
|---|
@@ -25,6 +23,8 @@ The project is for the following purposes:
25
23
26
24
Currently, this project is in early development.
27
25
26
+
Please refer to the [documentation](https://swiftpackageindex.com/OpenSwiftUIProject/OpenAttributeGraph/main/documentation/openattributegraph) for more information on it.
Copy file name to clipboardExpand all lines: Sources/OpenAttributeGraph/Attribute/Rule/Focus.swift
+29Lines changed: 29 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,35 @@
5
5
// Audited for RELEASE_2021
6
6
// Status: Complete
7
7
8
+
/// A rule that focuses on a specific property of another attribute using KeyPath.
9
+
///
10
+
/// `Focus` provides a way to create attributes that automatically track a specific property of another attribute. It uses Swift's KeyPath system to create a focused view of part of a larger data structure.
11
+
///
12
+
/// struct Person {
13
+
/// let name: String
14
+
/// let age: Int
15
+
/// }
16
+
///
17
+
/// @Attribute var person = Person(name: "Alice", age: 30)
18
+
/// let nameAttribute = Attribute(Focus(root: $person, keyPath: \.name))
19
+
/// // nameAttribute automatically updates when person.name changes
20
+
///
21
+
/// Focus is commonly used internally by OpenAttributeGraph's dynamic member lookup system to create property-specific attributes.
22
+
///
23
+
/// ## Key Features
24
+
///
25
+
/// - KeyPath-based focusing: Use any Swift KeyPath to focus on specific properties
26
+
/// - Automatic updates: Changes to the focused property automatically propagate
27
+
/// - Type safety: Full compile-time type checking for focused properties
28
+
/// - Efficient tracking: Only tracks changes to the specific focused property
29
+
///
30
+
/// ## Usage Pattern
31
+
///
32
+
/// Focus is ideal for:
33
+
/// - Creating focused views of complex data structures
34
+
/// - Implementing dynamic member lookup for attributes
35
+
/// - Breaking down large objects into smaller, more manageable attribute pieces
36
+
/// - Selective observation of specific properties
Copy file name to clipboardExpand all lines: Sources/OpenAttributeGraph/Attribute/Rule/StatefulRule.swift
+30Lines changed: 30 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,36 @@
7
7
8
8
publicimport OpenAttributeGraphCxx
9
9
10
+
/// A protocol for defining computed attributes that maintain state between evaluations.
11
+
///
12
+
/// `StatefulRule` extends the basic `Rule` concept by allowing rules to maintain mutable state between updates. This is useful for rules that need to track changes over time or maintain internal state.
13
+
///
14
+
/// struct CounterRule: StatefulRule {
15
+
/// typealias Value = Int
16
+
/// private var counter = 0
17
+
///
18
+
/// mutating func updateValue() {
19
+
/// counter += 1
20
+
/// value = counter
21
+
/// }
22
+
/// }
23
+
///
24
+
/// Unlike ``Rule``, `StatefulRule` allows mutation through the `updateValue()` method and provides direct access to the current value through the `value` property.
25
+
///
26
+
/// ## Key Features
27
+
///
28
+
/// - Mutable state: Rules can maintain and modify internal state
29
+
/// - Direct value access: Read and write the current value directly
30
+
/// - Context access: Access to rule evaluation context and attribute
31
+
/// - Lifecycle control: Manual control over when and how values update
32
+
///
33
+
/// ## Usage Pattern
34
+
///
35
+
/// StatefulRule is ideal for scenarios where you need to:
36
+
/// - Accumulate values over time
37
+
/// - Maintain counters or timers
38
+
/// - Implement complex state machines
39
+
/// - Cache expensive computations with custom invalidation
Copy file name to clipboardExpand all lines: Sources/OpenAttributeGraph/Attribute/Weak/WeakAttribute.swift
+27Lines changed: 27 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,33 @@
7
7
8
8
publicimport OpenAttributeGraphCxx
9
9
10
+
/// A weak reference property wrapper for attributes that prevents retain cycles.
11
+
///
12
+
/// `WeakAttribute` provides a way to hold weak references to attributes, preventing strong reference cycles in the attribute graph while still allowing access to reactive values.
13
+
///
14
+
/// @WeakAttribute var parentAttribute: SomeType?
15
+
///
16
+
/// // Safe access to potentially deallocated attribute
17
+
/// if let value = parentAttribute {
18
+
/// print("Parent value: \(value)")
19
+
/// }
20
+
///
21
+
/// The weak attribute automatically becomes `nil` when the referenced attribute is deallocated, providing memory-safe access to optional attribute references.
22
+
///
23
+
/// ## Key Features
24
+
///
25
+
/// - Weak references: Prevents retain cycles in attribute relationships
26
+
/// - Automatic nil assignment: Referenced attributes become nil when deallocated
27
+
/// - Dynamic member lookup: Access nested properties through weak references
28
+
/// - Optional semantics: All values are optional since references may be deallocated
29
+
///
30
+
/// ## Usage Pattern
31
+
///
32
+
/// WeakAttribute is essential for:
33
+
/// - Parent-child attribute relationships
34
+
/// - Observer patterns that don't own the observed attribute
35
+
/// - Breaking potential retain cycles in complex attribute graphs
36
+
/// - Optional attribute references in data structures
0 commit comments