Skip to content

Commit 6031a3a

Browse files
committed
Add comprehensive DocC documentation for Swift APIs
Extension files created: - StatefulRule.md - Stateful computed attributes with mutable state - WeakAttribute.md - Weak reference attributes preventing retain cycles - Graph.md - Central dependency coordinator and update management - Subgraph.md - Scoped computation contexts for isolation - RuleContext.md - Rule evaluation context and input access - Focus.md - KeyPath-based property focusing rules Source documentation added: - StatefulRule.swift - Brief protocol description - WeakAttribute.swift - Weak reference property wrapper docs - OptionalAttribute.swift - Optional attribute wrapper docs - Focus.swift - KeyPath focusing rule docs - RuleContext.swift - Evaluation context docs - CompareValues.swift - Value comparison function docs All APIs now have proper DocC documentation following OpenSwiftUI patterns
1 parent 8cc5128 commit 6031a3a

File tree

13 files changed

+327
-2
lines changed

13 files changed

+327
-2
lines changed

.spi.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
version: 1
22
builder:
33
configs:
4-
- swift_version: 6.0
5-
documentation_targets: [OpenAttributeGraph]
4+
- documentation_targets: [OpenAttributeGraph]

Sources/OpenAttributeGraph/Attribute/Optional/OptionalAttribute.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Audited for RELEASE_2021
66
// Status: Complete
77

8+
/// An optional attribute wrapper that may or may not contain a value.
89
@frozen
910
@propertyWrapper
1011
@dynamicMemberLookup

Sources/OpenAttributeGraph/Attribute/Rule/Focus.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Audited for RELEASE_2021
66
// Status: Complete
77

8+
/// A rule that focuses on a specific property of another attribute using KeyPath.
89
@frozen
910
public struct Focus<Root, Value>: Rule, CustomStringConvertible {
1011
public var root: Attribute<Root>

Sources/OpenAttributeGraph/Attribute/Rule/StatefulRule.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
public import OpenAttributeGraphCxx
99

10+
/// A protocol for defining computed attributes that maintain state between evaluations.
1011
public protocol StatefulRule: _AttributeBody {
1112
associatedtype Value
1213
static var initialValue: Value? { get }

Sources/OpenAttributeGraph/Attribute/RuleContext/RuleContext.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
public import OpenAttributeGraphCxx
99

10+
/// Context object providing access to rule evaluation state and input values.
1011
@frozen
1112
public struct RuleContext<Value>: Equatable {
1213
public var attribute: Attribute<Value>

Sources/OpenAttributeGraph/Attribute/Weak/WeakAttribute.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
public import OpenAttributeGraphCxx
99

10+
/// A weak reference property wrapper for attributes that prevents retain cycles.
1011
@frozen
1112
@propertyWrapper
1213
@dynamicMemberLookup
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# ``Focus``
2+
3+
A rule that focuses on a specific property of another attribute using KeyPath.
4+
5+
## Overview
6+
7+
`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.
8+
9+
struct Person {
10+
let name: String
11+
let age: Int
12+
}
13+
14+
@Attribute var person = Person(name: "Alice", age: 30)
15+
let nameAttribute = Attribute(Focus(root: $person, keyPath: \.name))
16+
// nameAttribute automatically updates when person.name changes
17+
18+
Focus is commonly used internally by OpenAttributeGraph's dynamic member lookup system to create property-specific attributes.
19+
20+
## Key Features
21+
22+
- KeyPath-based focusing: Use any Swift KeyPath to focus on specific properties
23+
- Automatic updates: Changes to the focused property automatically propagate
24+
- Type safety: Full compile-time type checking for focused properties
25+
- Efficient tracking: Only tracks changes to the specific focused property
26+
27+
## Usage Pattern
28+
29+
Focus is ideal for:
30+
- Creating focused views of complex data structures
31+
- Implementing dynamic member lookup for attributes
32+
- Breaking down large objects into smaller, more manageable attribute pieces
33+
- Selective observation of specific properties
34+
35+
## Topics
36+
37+
### Creating Focus Rules
38+
39+
- ``init(root:keyPath:)``
40+
41+
### Properties
42+
43+
- ``root``
44+
- ``keyPath``
45+
- ``value``
46+
47+
### Configuration
48+
49+
- ``flags``
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# ``Graph``
2+
3+
The central coordinator for attribute relationships and update cycles.
4+
5+
## Overview
6+
7+
`Graph` manages the dependency network between attributes and orchestrates efficient updates across the entire reactive system. It maintains a directed acyclic graph (DAG) of attribute dependencies and handles the propagation of changes.
8+
9+
The graph automatically tracks dependencies when attributes are accessed during rule evaluation, detects cycles, and batches updates for optimal performance.
10+
11+
## Key Features
12+
13+
- Dependency tracking: Automatically discovers and maintains attribute relationships
14+
- Cycle detection: Prevents and detects circular dependencies
15+
- Batch updates: Groups multiple changes for efficient processing
16+
- Update scheduling: Coordinates when and how attributes are recomputed
17+
- Performance monitoring: Profiling and debugging capabilities
18+
19+
## Update Propagation
20+
21+
When an attribute changes, the graph efficiently propagates updates through three phases:
22+
1. Mark phase: Changed attributes are marked as invalid
23+
2. Sweep phase: Dependent attributes are transitively marked
24+
3. Update phase: Values are recomputed in dependency order
25+
26+
## Topics
27+
28+
### Update Control
29+
30+
- ``withoutUpdate(_:)``
31+
- ``withoutSubgraphInvalidation(_:)``
32+
- ``withDeadline(_:_:)``
33+
34+
### Callbacks
35+
36+
- ``onInvalidation(_:)``
37+
- ``onUpdate(_:)``
38+
39+
### Performance Monitoring
40+
41+
- ``startProfiling()``
42+
- ``stopProfiling()``
43+
- ``resetProfile()``
44+
45+
### Statistics
46+
47+
- ``mainUpdates``
48+
49+
### Global Operations
50+
51+
- ``anyInputsChanged(excluding:)``
52+
53+
### Output Management
54+
55+
- ``outputValue()``
56+
- ``setOutputValue(_:)``
57+
58+
### Archive and Debug
59+
60+
- ``archiveJSON(name:)``
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# ``RuleContext``
2+
3+
Context object providing access to rule evaluation state and input values.
4+
5+
## Overview
6+
7+
`RuleContext` provides a structured way to access input values and manage state during rule evaluation. It offers type-safe access to dependent attributes and their values within the context of a specific rule execution.
8+
9+
The context ensures that dependency tracking is properly maintained while providing convenient access to input attributes.
10+
11+
## Key Features
12+
13+
- Type-safe input access: Access dependent attribute values with full type safety
14+
- Dependency tracking: Automatically tracks accessed attributes as dependencies
15+
- Value management: Direct access to current and changed values
16+
- Context isolation: Maintains evaluation context for proper dependency resolution
17+
18+
## Usage in Rules
19+
20+
RuleContext is typically used within ``StatefulRule`` implementations to access dependencies and manage the rule's output value:
21+
22+
struct MyRule: StatefulRule {
23+
let inputAttribute: Attribute<Int>
24+
25+
mutating func updateValue() {
26+
let inputValue = context[inputAttribute]
27+
value = inputValue * 2
28+
}
29+
}
30+
31+
## Topics
32+
33+
### Creating Context
34+
35+
- ``init(attribute:)``
36+
37+
### Input Access
38+
39+
- ``subscript(_:)-1g3wa``
40+
- ``subscript(_:)-6y4wa``
41+
- ``subscript(_:)-2h8nh``
42+
43+
### Value Management
44+
45+
- ``value``
46+
- ``hasValue``
47+
48+
### Change Tracking
49+
50+
- ``changedValueFlagged(options:)``
51+
- ``wasModified(options:)``
52+
53+
### Associated Attribute
54+
55+
- ``attribute``
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# ``StatefulRule``
2+
3+
A protocol for defining computed attributes that maintain state between evaluations.
4+
5+
## Overview
6+
7+
`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.
8+
9+
struct CounterRule: StatefulRule {
10+
typealias Value = Int
11+
private var counter = 0
12+
13+
mutating func updateValue() {
14+
counter += 1
15+
value = counter
16+
}
17+
}
18+
19+
Unlike ``Rule``, `StatefulRule` allows mutation through the `updateValue()` method and provides direct access to the current value through the `value` property.
20+
21+
## Key Features
22+
23+
- Mutable state: Rules can maintain and modify internal state
24+
- Direct value access: Read and write the current value directly
25+
- Context access: Access to rule evaluation context and attribute
26+
- Lifecycle control: Manual control over when and how values update
27+
28+
## Usage Pattern
29+
30+
StatefulRule is ideal for scenarios where you need to:
31+
- Accumulate values over time
32+
- Maintain counters or timers
33+
- Implement complex state machines
34+
- Cache expensive computations with custom invalidation
35+
36+
## Topics
37+
38+
### Protocol Requirements
39+
40+
- ``Value``
41+
- ``initialValue``
42+
- ``updateValue()``
43+
44+
### Value Management
45+
46+
- ``value``
47+
- ``hasValue``
48+
49+
### Context Access
50+
51+
- ``attribute``
52+
- ``context``

0 commit comments

Comments
 (0)