@@ -50,7 +50,8 @@ internal import _FoundationCollections
50
50
/// This takes into account the fraction completed in its children instances if children are present.
51
51
/// If `self` is indeterminate, the value will be 0.0.
52
52
public var fractionCompleted : Double {
53
- _ $observationRegistrar. access ( self , keyPath: \. fractionCompleted)
53
+ _ $observationRegistrar. access ( self , keyPath: \. totalCount)
54
+ _ $observationRegistrar. access ( self , keyPath: \. completedCount)
54
55
return state. withLock { state in
55
56
state. getFractionCompleted ( )
56
57
}
@@ -59,7 +60,7 @@ internal import _FoundationCollections
59
60
/// The state of initialization of `totalCount`.
60
61
/// If `totalCount` is `nil`, the value will be `true`.
61
62
public var isIndeterminate : Bool {
62
- _ $observationRegistrar. access ( self , keyPath: \. isIndeterminate )
63
+ _ $observationRegistrar. access ( self , keyPath: \. totalCount )
63
64
return state. withLock { state in
64
65
state. getIsIndeterminate ( )
65
66
}
@@ -68,7 +69,8 @@ internal import _FoundationCollections
68
69
/// The state of completion of work.
69
70
/// If `completedCount` >= `totalCount`, the value will be `true`.
70
71
public var isFinished : Bool {
71
- _ $observationRegistrar. access ( self , keyPath: \. isFinished)
72
+ _ $observationRegistrar. access ( self , keyPath: \. totalCount)
73
+ _ $observationRegistrar. access ( self , keyPath: \. completedCount)
72
74
return state. withLock { state in
73
75
state. getIsFinished ( )
74
76
}
@@ -178,52 +180,48 @@ internal import _FoundationCollections
178
180
/// Increases `completedCount` by `count`.
179
181
/// - Parameter count: Units of work.
180
182
public func complete( count: Int ) {
181
- _ $observationRegistrar. withMutation ( of: self , keyPath: \. fractionCompleted) {
182
- _ $observationRegistrar. withMutation ( of: self , keyPath: \. completedCount) {
183
+ _ $observationRegistrar. withMutation ( of: self , keyPath: \. completedCount) {
184
+ let parents : [ ParentState ] ? = state. withLock { state in
185
+ guard state. selfFraction. completed != ( state. selfFraction. completed + count) else {
186
+ return nil
187
+ }
188
+
189
+ state. complete ( by: count)
190
+
191
+ return state. parents
192
+ }
193
+ if let parents = parents {
194
+ markSelfDirty ( parents: parents)
195
+ }
196
+ }
197
+ }
198
+
199
+ public func setCounts( _ counts: ( _ completed: inout Int , _ total: inout Int ? ) -> Void ) {
200
+ _ $observationRegistrar. withMutation ( of: self , keyPath: \. completedCount) {
201
+ _ $observationRegistrar. withMutation ( of: self , keyPath: \. totalCount) {
183
202
let parents : [ ParentState ] ? = state. withLock { state in
184
- guard state. selfFraction. completed != ( state. selfFraction. completed + count) else {
203
+ var completed = state. selfFraction. completed
204
+ var total = state. selfFraction. total
205
+
206
+ counts ( & completed, & total)
207
+
208
+ guard state. selfFraction. completed != completed || state. selfFraction. total != total else {
185
209
return nil
186
210
}
187
211
188
- state. complete ( by: count)
212
+ state. selfFraction. completed = completed
213
+ state. selfFraction. total = total
189
214
190
215
return state. parents
191
216
}
217
+
192
218
if let parents = parents {
193
219
markSelfDirty ( parents: parents)
194
220
}
195
221
}
196
222
}
197
223
}
198
224
199
- public func setCounts( _ counts: ( _ completed: inout Int , _ total: inout Int ? ) -> Void ) {
200
- _ $observationRegistrar. withMutation ( of: self , keyPath: \. fractionCompleted) {
201
- _ $observationRegistrar. withMutation ( of: self , keyPath: \. completedCount) {
202
- _ $observationRegistrar. withMutation ( of: self , keyPath: \. totalCount) {
203
- let parents : [ ParentState ] ? = state. withLock { state in
204
- var completed = state. selfFraction. completed
205
- var total = state. selfFraction. total
206
-
207
- counts ( & completed, & total)
208
-
209
- guard state. selfFraction. completed != completed || state. selfFraction. total != total else {
210
- return nil
211
- }
212
-
213
- state. selfFraction. completed = completed
214
- state. selfFraction. total = total
215
-
216
- return state. parents
217
- }
218
-
219
- if let parents = parents {
220
- markSelfDirty ( parents: parents)
221
- }
222
- }
223
- }
224
- }
225
- }
226
-
227
225
// MARK: Internal Observation Support for Extensions
228
226
229
227
/// Provides access to the observation registrar for use in extensions.
@@ -242,7 +240,6 @@ internal import _FoundationCollections
242
240
internal func getProgressFraction( ) -> ProgressFraction {
243
241
return state. withLock { state in
244
242
return state. selfFraction
245
-
246
243
}
247
244
}
248
245
@@ -263,11 +260,13 @@ internal import _FoundationCollections
263
260
}
264
261
265
262
private func markChildDirty( at position: Int ) {
266
- let parents : [ ParentState ] ? = state. withLock { state in
267
- state. markChildDirty ( at: position)
268
- }
269
- if let parents = parents {
270
- markSelfDirty ( parents: parents)
263
+ _ $observationRegistrar. withMutation ( of: self , keyPath: \. completedCount) {
264
+ let parents : [ ParentState ] ? = state. withLock { state in
265
+ state. markChildDirty ( at: position)
266
+ }
267
+ if let parents = parents {
268
+ markSelfDirty ( parents: parents)
269
+ }
271
270
}
272
271
}
273
272
0 commit comments