Skip to content

Commit 0234156

Browse files
committed
Use PartialKeyPath instead of closures
1 parent b800d52 commit 0234156

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

Sources/Defaults+Syncing.swift

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,25 @@
2525
#if !os(Linux)
2626

2727
public extension DefaultsAdapter {
28-
func syncKeys(_ keys: [(KeyStore) -> RawKeyRepresentable]) {
29-
let keys = Set(keys.map { $0(keyStore)._key })
30-
syncer.syncedKeys = keys
28+
29+
func startSyncing(for keyPaths: PartialKeyPath<KeyStore>...) {
30+
let rawKeys = keyPaths.map { keyStore[keyPath: $0] }.compactMap { $0 as? RawKeyRepresentable }.map { $0._key }
31+
rawKeys.forEach {
32+
syncer.syncedKeys.insert($0)
33+
}
34+
}
35+
36+
func stopSyncing(for keyPaths: PartialKeyPath<KeyStore>...) {
37+
let rawKeys = keyPaths.map { keyStore[keyPath: $0] }.compactMap { $0 as? RawKeyRepresentable }.map { $0._key }
38+
rawKeys.forEach {
39+
syncer.syncedKeys.remove($0)
40+
}
3141
}
42+
43+
func stopSyncingAll() {
44+
syncer.syncedKeys = []
45+
}
46+
3247
}
3348

3449
#endif

Sources/DefaultsKey.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
import Foundation
2626

27-
public protocol RawKeyRepresentable {
27+
internal protocol RawKeyRepresentable {
2828
var _key: String { get }
2929
}
3030

0 commit comments

Comments
 (0)