Skip to content

Commit 36f09f5

Browse files
committed
correct placement of access and withMutation calls
1 parent bab3b11 commit 36f09f5

File tree

3 files changed

+101
-111
lines changed

3 files changed

+101
-111
lines changed

Sources/FoundationEssentials/ProgressManager/ProgressManager+Properties+Accessors.swift

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extension ProgressManager {
2525
/// - Parameter key: A key path to the custom integer property type.
2626
public subscript<P: Property>(dynamicMember key: KeyPath<ProgressManager.Properties, P.Type>) -> Int where P.Value == Int, P.Summary == Int {
2727
get {
28-
accessObservation(keyPath: ProgressManager.additionalPropertiesKeyPath.withLock { $0 })
28+
self.access(keyPath: ProgressManager.additionalPropertiesKeyPath.withLock { $0 })
2929
return state.withLock { state in
3030
if P.self == ProgressManager.Properties.TotalFileCount.self {
3131
return state.totalFileCount
@@ -38,7 +38,7 @@ extension ProgressManager {
3838
}
3939

4040
set {
41-
mutateObservation(of: ProgressManager.additionalPropertiesKeyPath.withLock { $0 }) {
41+
self.withMutation(keyPath: ProgressManager.additionalPropertiesKeyPath.withLock { $0 }) {
4242
let parents: [ParentState]? = state.withLock { state in
4343
if P.self == ProgressManager.Properties.TotalFileCount.self {
4444
guard newValue != state.totalFileCount else {
@@ -83,7 +83,7 @@ extension ProgressManager {
8383
/// - Parameter key: A key path to the custom unsigned integer property type.
8484
public subscript<P: Property>(dynamicMember key: KeyPath<ProgressManager.Properties, P.Type>) -> UInt64 where P.Value == UInt64, P.Summary == UInt64 {
8585
get {
86-
accessObservation(keyPath: ProgressManager.additionalPropertiesKeyPath.withLock { $0 })
86+
self.access(keyPath: ProgressManager.additionalPropertiesKeyPath.withLock { $0 })
8787
return state.withLock { state in
8888
if P.self == ProgressManager.Properties.TotalByteCount.self {
8989
return state.totalByteCount
@@ -96,7 +96,7 @@ extension ProgressManager {
9696
}
9797

9898
set {
99-
mutateObservation(of: ProgressManager.additionalPropertiesKeyPath.withLock { $0 }) {
99+
self.withMutation(keyPath: ProgressManager.additionalPropertiesKeyPath.withLock { $0 }) {
100100
let parents: [ParentState]? = state.withLock { state in
101101
if P.self == ProgressManager.Properties.TotalByteCount.self {
102102
guard newValue != state.totalByteCount else {
@@ -140,14 +140,14 @@ extension ProgressManager {
140140
/// - Parameter key: A key path to the custom double property type.
141141
public subscript<P: Property>(dynamicMember key: KeyPath<ProgressManager.Properties, P.Type>) -> P.Value where P.Value == Double, P.Summary == Double {
142142
get {
143-
accessObservation(keyPath: ProgressManager.additionalPropertiesKeyPath.withLock { $0 })
143+
self.access(keyPath: ProgressManager.additionalPropertiesKeyPath.withLock { $0 })
144144
return state.withLock { state in
145145
return state.propertiesDouble[MetatypeWrapper(P.self)] ?? P.defaultValue
146146
}
147147
}
148148

149149
set {
150-
mutateObservation(of: ProgressManager.additionalPropertiesKeyPath.withLock { $0 }) {
150+
self.withMutation(keyPath: ProgressManager.additionalPropertiesKeyPath.withLock { $0 }) {
151151
let parents: [ParentState]? = state.withLock { state in
152152
guard newValue != state.propertiesDouble[MetatypeWrapper(P.self)] else {
153153
return nil
@@ -171,14 +171,14 @@ extension ProgressManager {
171171
/// - Parameter key: A key path to the custom string property type.
172172
public subscript<P: Property>(dynamicMember key: KeyPath<ProgressManager.Properties, P.Type>) -> String? where P.Value == String?, P.Summary == [String?] {
173173
get {
174-
accessObservation(keyPath: ProgressManager.additionalPropertiesKeyPath.withLock { $0 })
174+
self.access(keyPath: ProgressManager.additionalPropertiesKeyPath.withLock { $0 })
175175
return state.withLock { state in
176176
return state.propertiesString[MetatypeWrapper(P.self)] ?? P.defaultValue
177177
}
178178
}
179179

180180
set {
181-
mutateObservation(of: ProgressManager.additionalPropertiesKeyPath.withLock { $0 }) {
181+
self.withMutation(keyPath: ProgressManager.additionalPropertiesKeyPath.withLock { $0 }) {
182182
let parents: [ParentState]? = state.withLock { state in
183183
guard newValue != state.propertiesString[MetatypeWrapper(P.self)] else {
184184
return nil
@@ -202,14 +202,14 @@ extension ProgressManager {
202202
/// - Parameter key: A key path to the custom URL property type.
203203
public subscript<P: Property>(dynamicMember key: KeyPath<ProgressManager.Properties, P.Type>) -> URL? where P.Value == URL?, P.Summary == [URL?] {
204204
get {
205-
accessObservation(keyPath: ProgressManager.additionalPropertiesKeyPath.withLock { $0 })
205+
self.access(keyPath: ProgressManager.additionalPropertiesKeyPath.withLock { $0 })
206206
return state.withLock { state in
207207
return state.propertiesURL[MetatypeWrapper(P.self)] ?? P.defaultValue
208208
}
209209
}
210210

211211
set {
212-
mutateObservation(of: ProgressManager.additionalPropertiesKeyPath.withLock { $0 }) {
212+
self.withMutation(keyPath: ProgressManager.additionalPropertiesKeyPath.withLock { $0 }) {
213213
let parents: [ParentState]? = state.withLock { state in
214214
guard newValue != state.propertiesURL[MetatypeWrapper(P.self)] else {
215215
return nil
@@ -233,7 +233,7 @@ extension ProgressManager {
233233
/// - Parameter key: A key path to the custom unsigned integer property type.
234234
public subscript<P: Property>(dynamicMember key: KeyPath<ProgressManager.Properties, P.Type>) -> UInt64 where P.Value == UInt64, P.Summary == [UInt64] {
235235
get {
236-
accessObservation(keyPath: ProgressManager.additionalPropertiesKeyPath.withLock { $0 })
236+
self.access(keyPath: ProgressManager.additionalPropertiesKeyPath.withLock { $0 })
237237
return state.withLock { state in
238238
if P.self == ProgressManager.Properties.Throughput.self {
239239
return state.throughput
@@ -244,7 +244,7 @@ extension ProgressManager {
244244
}
245245

246246
set {
247-
mutateObservation(of: ProgressManager.additionalPropertiesKeyPath.withLock { $0 }) {
247+
self.withMutation(keyPath: ProgressManager.additionalPropertiesKeyPath.withLock { $0 }) {
248248
let parents: [ParentState]? = state.withLock { state in
249249
if P.self == ProgressManager.Properties.Throughput.self {
250250
guard newValue != state.throughput else {
@@ -280,7 +280,7 @@ extension ProgressManager {
280280
/// - Parameter key: A key path to the custom duration property type.
281281
public subscript<P: Property>(dynamicMember key: KeyPath<ProgressManager.Properties, P.Type>) -> Duration where P.Value == Duration, P.Summary == Duration {
282282
get {
283-
accessObservation(keyPath: ProgressManager.additionalPropertiesKeyPath.withLock { $0 })
283+
self.access(keyPath: ProgressManager.additionalPropertiesKeyPath.withLock { $0 })
284284
return state.withLock { state in
285285
if P.self == ProgressManager.Properties.EstimatedTimeRemaining.self {
286286
return state.estimatedTimeRemaining
@@ -291,7 +291,7 @@ extension ProgressManager {
291291
}
292292

293293
set {
294-
mutateObservation(of: ProgressManager.additionalPropertiesKeyPath.withLock { $0 }) {
294+
self.withMutation(keyPath: ProgressManager.additionalPropertiesKeyPath.withLock { $0 }) {
295295
let parents: [ParentState]? = state.withLock { state in
296296
if P.self == ProgressManager.Properties.EstimatedTimeRemaining.self {
297297
guard newValue != state.estimatedTimeRemaining else {
@@ -329,7 +329,7 @@ extension ProgressManager {
329329
/// where both the value and summary types are `Int`.
330330
/// - Returns: An `Int` summary value for the specified property.
331331
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == Int, P.Summary == Int {
332-
accessObservation(keyPath: ProgressManager.additionalPropertiesKeyPath.withLock { $0 })
332+
self.access(keyPath: ProgressManager.additionalPropertiesKeyPath.withLock { $0 })
333333
if property.self == ProgressManager.Properties.TotalFileCount.self {
334334
return updatedFileCount(type: .total)
335335
} else if property.self == ProgressManager.Properties.CompletedFileCount.self {
@@ -348,7 +348,7 @@ extension ProgressManager {
348348
/// where both the value and summary types are `UInt64`.
349349
/// - Returns: An `UInt64` summary value for the specified property.
350350
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == UInt64, P.Summary == UInt64 {
351-
accessObservation(keyPath: ProgressManager.additionalPropertiesKeyPath.withLock { $0 })
351+
self.access(keyPath: ProgressManager.additionalPropertiesKeyPath.withLock { $0 })
352352
if property.self == ProgressManager.Properties.TotalByteCount.self {
353353
return updatedByteCount(type: .total)
354354
} else if property.self == ProgressManager.Properties.CompletedByteCount.self {
@@ -367,7 +367,7 @@ extension ProgressManager {
367367
/// where both the value and summary types are `Double`.
368368
/// - Returns: A `Double` summary value for the specified property.
369369
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == Double, P.Summary == Double {
370-
accessObservation(keyPath: ProgressManager.additionalPropertiesKeyPath.withLock { $0 })
370+
self.access(keyPath: ProgressManager.additionalPropertiesKeyPath.withLock { $0 })
371371
return updatedDoubleSummary(property: MetatypeWrapper(property))
372372
}
373373

@@ -380,7 +380,7 @@ extension ProgressManager {
380380
/// where both the value type is `String?` and the summary type is `[String?]`.
381381
/// - Returns: A `[String?]` summary value for the specified property.
382382
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == String?, P.Summary == [String?] {
383-
accessObservation(keyPath: ProgressManager.additionalPropertiesKeyPath.withLock { $0 })
383+
self.access(keyPath: ProgressManager.additionalPropertiesKeyPath.withLock { $0 })
384384
return updatedStringSummary(property: MetatypeWrapper(property))
385385
}
386386

@@ -393,7 +393,7 @@ extension ProgressManager {
393393
/// where the value type is `URL?` and the summary type is `[URL?]`.
394394
/// - Returns: A `[URL?]` summary value for the specified property.
395395
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == URL?, P.Summary == [URL?] {
396-
accessObservation(keyPath: ProgressManager.additionalPropertiesKeyPath.withLock { $0 })
396+
self.access(keyPath: ProgressManager.additionalPropertiesKeyPath.withLock { $0 })
397397
return updatedURLSummary(property: MetatypeWrapper(property))
398398
}
399399

@@ -406,7 +406,7 @@ extension ProgressManager {
406406
/// where the value type is `UInt64` and the summary type is `[UInt64]`.
407407
/// - Returns: A `[UInt64]` summary value for the specified property.
408408
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == UInt64, P.Summary == [UInt64] {
409-
accessObservation(keyPath: ProgressManager.additionalPropertiesKeyPath.withLock { $0 })
409+
self.access(keyPath: ProgressManager.additionalPropertiesKeyPath.withLock { $0 })
410410
if property.self == ProgressManager.Properties.Throughput.self {
411411
return updatedThroughput()
412412
} else {
@@ -423,7 +423,7 @@ extension ProgressManager {
423423
/// where the value type is `Duration` and the summary type is `Duration`.
424424
/// - Returns: A `Duration` summary value for the specified property.
425425
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == Duration, P.Summary == Duration {
426-
accessObservation(keyPath: ProgressManager.additionalPropertiesKeyPath.withLock { $0 })
426+
self.access(keyPath: ProgressManager.additionalPropertiesKeyPath.withLock { $0 })
427427
if property.self == ProgressManager.Properties.EstimatedTimeRemaining.self {
428428
return updatedEstimatedTimeRemaining()
429429
} else {

Sources/FoundationEssentials/ProgressManager/ProgressManager+Properties+Helpers.swift

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -337,57 +337,45 @@ extension ProgressManager {
337337
}
338338

339339
internal func markChildDirty(property: ProgressManager.Properties.TotalFileCount.Type, at position: Int) {
340-
mutateObservation(of: ProgressManager.additionalPropertiesKeyPath.withLock { $0 }) {
341-
let parents = state.withLock { state in
342-
state.markChildDirty(property: property, at: position)
343-
}
344-
markSelfDirty(property: property, parents: parents)
340+
let parents = state.withLock { state in
341+
state.markChildDirty(property: property, at: position)
345342
}
343+
markSelfDirty(property: property, parents: parents)
346344
}
347345

348346
internal func markChildDirty(property: ProgressManager.Properties.CompletedFileCount.Type, at position: Int) {
349-
mutateObservation(of: ProgressManager.additionalPropertiesKeyPath.withLock { $0 }) {
350-
let parents = state.withLock { state in
351-
state.markChildDirty(property: property, at: position)
352-
}
353-
markSelfDirty(property: property, parents: parents)
347+
let parents = state.withLock { state in
348+
state.markChildDirty(property: property, at: position)
354349
}
350+
markSelfDirty(property: property, parents: parents)
355351
}
356352

357353
internal func markChildDirty(property: ProgressManager.Properties.TotalByteCount.Type, at position: Int) {
358-
mutateObservation(of: ProgressManager.additionalPropertiesKeyPath.withLock { $0 }) {
359-
let parents = state.withLock { state in
360-
state.markChildDirty(property: property, at: position)
361-
}
362-
markSelfDirty(property: property, parents: parents)
354+
let parents = state.withLock { state in
355+
state.markChildDirty(property: property, at: position)
363356
}
357+
markSelfDirty(property: property, parents: parents)
364358
}
365359

366360
internal func markChildDirty(property: ProgressManager.Properties.CompletedByteCount.Type, at position: Int) {
367-
mutateObservation(of: ProgressManager.additionalPropertiesKeyPath.withLock { $0 }) {
368-
let parents = state.withLock { state in
369-
state.markChildDirty(property: property, at: position)
370-
}
371-
markSelfDirty(property: property, parents: parents)
361+
let parents = state.withLock { state in
362+
state.markChildDirty(property: property, at: position)
372363
}
364+
markSelfDirty(property: property, parents: parents)
373365
}
374366

375367
internal func markChildDirty(property: ProgressManager.Properties.Throughput.Type, at position: Int) {
376-
mutateObservation(of: ProgressManager.additionalPropertiesKeyPath.withLock { $0 }) {
377-
let parents = state.withLock { state in
378-
state.markChildDirty(property: property, at: position)
379-
}
380-
markSelfDirty(property: property, parents: parents)
368+
let parents = state.withLock { state in
369+
state.markChildDirty(property: property, at: position)
381370
}
371+
markSelfDirty(property: property, parents: parents)
382372
}
383373

384374
internal func markChildDirty(property: ProgressManager.Properties.EstimatedTimeRemaining.Type, at position: Int) {
385-
mutateObservation(of: ProgressManager.additionalPropertiesKeyPath.withLock { $0 }) {
386-
let parents = state.withLock { state in
387-
state.markChildDirty(property: property, at: position)
388-
}
389-
markSelfDirty(property: property, parents: parents)
375+
let parents = state.withLock { state in
376+
state.markChildDirty(property: property, at: position)
390377
}
378+
markSelfDirty(property: property, parents: parents)
391379
}
392380

393381
//MARK: Method to preserve values of properties upon deinit

0 commit comments

Comments
 (0)