@@ -1044,60 +1044,62 @@ open class _ViewList_ID_Views: RandomAccessCollection, Equatable {
1044
1044
@available ( * , unavailable)
1045
1045
extension ViewList . ID . Views : Sendable { }
1046
1046
1047
- // MARK: - ViewListOutputs + Extension [TODO]
1047
+ // MARK: - UnaryViewGenerator
1048
1048
1049
- extension _ViewListOutputs {
1050
- private static func staticList ( _ elements : any ViewList . Elements , inputs: _ViewListInputs , staticCount : Int ) -> _ViewListOutputs {
1051
- preconditionFailure ( " TODO " )
1052
- }
1049
+ public protocol UnaryViewGenerator {
1050
+ func makeView ( inputs: _ViewInputs , indirectMap : IndirectAttributeMap ? ) -> _ViewOutputs
1051
+ func tryToReuse ( by other : Self , indirectMap : IndirectAttributeMap , testOnly : Bool ) -> Bool
1052
+ }
1053
1053
1054
- package static func unaryViewList< V> ( view: _GraphValue < V > , inputs: _ViewListInputs ) -> _ViewListOutputs where V: View {
1055
- preconditionFailure ( " TODO " )
1056
- }
1054
+ public struct BodyUnaryViewGenerator < V> : UnaryViewGenerator {
1055
+ let body : ViewList . Elements . MakeElement
1057
1056
1058
- package static func unaryViewList < T > ( viewType : T . Type = T . self , inputs: _ViewListInputs , body : @escaping ( _ViewInputs ) -> _ViewOutputs ) -> _ViewListOutputs {
1059
- preconditionFailure ( " TODO " )
1057
+ public func makeView ( inputs: _ViewInputs , indirectMap : IndirectAttributeMap ? ) -> _ViewOutputs {
1058
+ body ( inputs )
1060
1059
}
1061
1060
1062
- package static func emptyViewList( inputs: _ViewListInputs ) -> _ViewListOutputs {
1063
- if inputs. options. contains ( . isNonEmptyParent) {
1064
- nonEmptyParentViewList ( inputs: inputs)
1065
- } else {
1066
- staticList ( EmptyViewListElements ( ) , inputs: inputs, staticCount: 0 )
1061
+ public func tryToReuse( by other: BodyUnaryViewGenerator < V > , indirectMap: IndirectAttributeMap , testOnly: Bool ) -> Bool {
1062
+ // FIXME
1063
+ // 1. pass body to OGCompareValues directly instaed of withUnsafePointer
1064
+ // 2. Add 0x103 case instead of rawValue
1065
+ guard compareValues ( body, other. body, mode: . init( rawValue: 0x103 ) ) else {
1066
+ ReuseTrace . traceReuseBodyMismatchedFailure ( )
1067
+ Log . graphReuse ( " Reuse failed: \( Self . self) failed comparison " )
1068
+ return false
1067
1069
}
1070
+ return true
1068
1071
}
1072
+ }
1069
1073
1070
- static func nonEmptyParentViewList( inputs: _ViewListInputs ) -> _ViewListOutputs {
1071
- preconditionFailure ( " TODO " )
1072
- }
1073
-
1074
- package func makeAttribute( inputs: _ViewListInputs ) -> Attribute < any ViewList > {
1075
- preconditionFailure ( " TODO " )
1076
- }
1077
-
1078
- package func makeAttribute( viewInputs: _ViewInputs ) -> Attribute < any ViewList > {
1079
- preconditionFailure ( " TODO " )
1080
- }
1081
-
1082
- package static func makeModifiedList( list: Attribute < any ViewList > , modifier: ListModifier ? ) -> Attribute < any ViewList > {
1083
- preconditionFailure ( " TODO " )
1084
- }
1074
+ public struct TypedUnaryViewGenerator < V> : UnaryViewGenerator where V: View {
1075
+ let view : WeakAttribute < V >
1085
1076
1086
- package mutating func multiModifier< T> ( _ modifier: _GraphValue < T > , inputs: _ViewListInputs ) where T: ViewModifier {
1087
- preconditionFailure ( " TODO " )
1077
+ public func makeView( inputs: _ViewInputs , indirectMap: IndirectAttributeMap ? ) -> _ViewOutputs {
1078
+ guard var view = view. attribute else {
1079
+ return . init( )
1080
+ }
1081
+ if let indirectMap {
1082
+ view. makeReusable ( indirectMap: indirectMap)
1083
+ }
1084
+ return V . makeDebuggableView ( view: _GraphValue ( view) , inputs: inputs)
1088
1085
}
1089
1086
1090
- package static func concat( _ outputs: [ _ViewListOutputs ] , inputs: _ViewListInputs ) -> _ViewListOutputs {
1091
- preconditionFailure ( " TODO " )
1087
+ public func tryToReuse( by other: TypedUnaryViewGenerator < V > , indirectMap: IndirectAttributeMap , testOnly: Bool ) -> Bool {
1088
+ guard let view = view. attribute, let otherView = other. view. attribute else {
1089
+ Log . graphReuse ( " Reuse failed: missing attribute for \( V . self) " )
1090
+ return false
1091
+ }
1092
+ return view. tryToReuse ( by: otherView, indirectMap: indirectMap, testOnly: testOnly)
1092
1093
}
1093
1094
}
1094
1095
1095
- // TODO:
1096
- private struct UnaryElements < Value> : ViewList . Elements {
1097
- var body : Value
1096
+ // MARK: - UnaryElements
1097
+
1098
+ private struct UnaryElements < Generator> : ViewList . Elements where Generator: UnaryViewGenerator {
1099
+ var body : Generator
1098
1100
var baseInputs : _GraphInputs
1099
1101
1100
- init ( body: Value , baseInputs: _GraphInputs ) {
1102
+ init ( body: Generator , baseInputs: _GraphInputs ) {
1101
1103
self . body = body
1102
1104
self . baseInputs = baseInputs
1103
1105
}
@@ -1120,6 +1122,64 @@ private struct UnaryElements<Value>: ViewList.Elements {
1120
1122
indirectMap: IndirectAttributeMap ,
1121
1123
testOnly: Bool
1122
1124
) -> Bool {
1125
+ guard let other = other as? UnaryElements else {
1126
+ Log . graphReuse ( " Reuse failed: other is not Unary " )
1127
+ ReuseTrace . traceReuseUnaryElementExpectedFailure ( type ( of: other) )
1128
+ return false
1129
+ }
1130
+ // BodyInput
1131
+ preconditionFailure ( " TODO " )
1132
+ }
1133
+ }
1134
+
1135
+ // MARK: - ViewListOutputs + Extension [TODO]
1136
+
1137
+ extension _ViewListOutputs {
1138
+ private static func staticList( _ elements: any ViewList . Elements , inputs: _ViewListInputs , staticCount: Int ) -> _ViewListOutputs {
1139
+ preconditionFailure ( " TODO " )
1140
+ }
1141
+
1142
+ static func nonEmptyParentViewList( inputs: _ViewListInputs ) -> _ViewListOutputs {
1143
+ preconditionFailure ( " TODO " )
1144
+ }
1145
+
1146
+ package static func unaryViewList< V> ( view: _GraphValue < V > , inputs: _ViewListInputs ) -> _ViewListOutputs where V: View {
1147
+ let generator = TypedUnaryViewGenerator ( view: . init( view. value) )
1148
+ let elements = UnaryElements ( body: generator, baseInputs: inputs. base)
1149
+ return staticList ( elements, inputs: inputs, staticCount: 1 )
1150
+ }
1151
+
1152
+ package static func unaryViewList< T> ( viewType: T . Type = T . self, inputs: _ViewListInputs , body: @escaping ViewList . Elements . MakeElement ) -> _ViewListOutputs {
1153
+ let generator = BodyUnaryViewGenerator < T > ( body: body)
1154
+ let elements = UnaryElements ( body: generator, baseInputs: inputs. base)
1155
+ return staticList ( elements, inputs: inputs, staticCount: 1 )
1156
+ }
1157
+
1158
+ package static func emptyViewList( inputs: _ViewListInputs ) -> _ViewListOutputs {
1159
+ if inputs. options. contains ( . isNonEmptyParent) {
1160
+ nonEmptyParentViewList ( inputs: inputs)
1161
+ } else {
1162
+ staticList ( EmptyViewListElements ( ) , inputs: inputs, staticCount: 0 )
1163
+ }
1164
+ }
1165
+
1166
+ package func makeAttribute( inputs: _ViewListInputs ) -> Attribute < any ViewList > {
1167
+ preconditionFailure ( " TODO " )
1168
+ }
1169
+
1170
+ package func makeAttribute( viewInputs: _ViewInputs ) -> Attribute < any ViewList > {
1171
+ preconditionFailure ( " TODO " )
1172
+ }
1173
+
1174
+ package static func makeModifiedList( list: Attribute < any ViewList > , modifier: ListModifier ? ) -> Attribute < any ViewList > {
1175
+ preconditionFailure ( " TODO " )
1176
+ }
1177
+
1178
+ package mutating func multiModifier< T> ( _ modifier: _GraphValue < T > , inputs: _ViewListInputs ) where T: ViewModifier {
1179
+ preconditionFailure ( " TODO " )
1180
+ }
1181
+
1182
+ package static func concat( _ outputs: [ _ViewListOutputs ] , inputs: _ViewListInputs ) -> _ViewListOutputs {
1123
1183
preconditionFailure ( " TODO " )
1124
1184
}
1125
1185
}
0 commit comments