Skip to content

Commit 7c003de

Browse files
committed
Rename functions in StorageObservationRegistry
1 parent cb85b99 commit 7c003de

File tree

6 files changed

+27
-27
lines changed

6 files changed

+27
-27
lines changed

Source/Shared/Storage/HybridStorage.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Foundation
44
public final class HybridStorage<T> {
55
public let memoryStorage: MemoryStorage<T>
66
public let diskStorage: DiskStorage<T>
7-
public let registry = StorageObservationRegistry<HybridStorage>()
7+
public let storageObservationRegistry = StorageObservationRegistry<HybridStorage>()
88

99
public init(memoryStorage: MemoryStorage<T>, diskStorage: DiskStorage<T>) {
1010
self.memoryStorage = memoryStorage
@@ -27,25 +27,25 @@ extension HybridStorage: StorageAware {
2727
public func removeObject(forKey key: String) throws {
2828
memoryStorage.removeObject(forKey: key)
2929
try diskStorage.removeObject(forKey: key)
30-
registry.notifyObservers(about: .singleDeletion, in: self)
30+
storageObservationRegistry.notifyObservers(about: .singleDeletion, in: self)
3131
}
3232

3333
public func setObject(_ object: T, forKey key: String, expiry: Expiry? = nil) throws {
3434
memoryStorage.setObject(object, forKey: key, expiry: expiry)
3535
try diskStorage.setObject(object, forKey: key, expiry: expiry)
36-
registry.notifyObservers(about: .addition, in: self)
36+
storageObservationRegistry.notifyObservers(about: .addition, in: self)
3737
}
3838

3939
public func removeAll() throws {
4040
memoryStorage.removeAll()
4141
try diskStorage.removeAll()
42-
registry.notifyObservers(about: .allDeletion, in: self)
42+
storageObservationRegistry.notifyObservers(about: .allDeletion, in: self)
4343
}
4444

4545
public func removeExpiredObjects() throws {
4646
memoryStorage.removeExpiredObjects()
4747
try diskStorage.removeExpiredObjects()
48-
registry.notifyObservers(about: .expiredDeletion, in: self)
48+
storageObservationRegistry.notifyObservers(about: .expiredDeletion, in: self)
4949
}
5050
}
5151

Source/Shared/Storage/Storage.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public final class Storage<T> {
88
let syncStorage: SyncStorage<T>
99
let asyncStorage: AsyncStorage<T>
1010

11-
public let registry = StorageObservationRegistry<Storage>()
11+
public let storageObservationRegistry = StorageObservationRegistry<Storage>()
1212

1313
/// Initialize storage with configuration options.
1414
///
@@ -54,9 +54,9 @@ public final class Storage<T> {
5454
}
5555

5656
private func subscribeToChanges(in storage: HybridStorage<T>) {
57-
storage.registry.register { [weak self] _, change in
57+
storage.storageObservationRegistry.addObservation { [weak self] _, change in
5858
guard let strongSelf = self else { return }
59-
self?.registry.notifyObservers(about: change, in: strongSelf)
59+
self?.storageObservationRegistry.notifyObservers(about: change, in: strongSelf)
6060
}
6161
}
6262
}

Source/Shared/Storage/StorageObservationRegistry.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ public final class StorageObservationRegistry<T: StorageAware> {
55
private(set) var observations = [UUID: Observation]()
66

77
@discardableResult
8-
public func register(observation: @escaping Observation) -> ObservationToken {
8+
public func addObservation(_ observation: @escaping Observation) -> ObservationToken {
99
let id = UUID()
1010
observations[id] = observation
1111

@@ -14,11 +14,11 @@ public final class StorageObservationRegistry<T: StorageAware> {
1414
}
1515
}
1616

17-
public func deregister(token: ObservationToken) {
17+
public func removeObservation(token: ObservationToken) {
1818
token.cancel()
1919
}
2020

21-
public func deregisterAll() {
21+
public func removeAllObservations() {
2222
observations.removeAll()
2323
}
2424

Tests/iOS/Tests/Storage/HybridStorageTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,10 @@ final class HybridStorageTests: XCTestCase {
157157
}
158158
}
159159

160-
func testRegisterObservations() throws {
160+
func testAddObservations() throws {
161161
var changes = [StorageChange]()
162162

163-
storage.registry.register { storage, change in
163+
storage.storageObservationRegistry.addObservation { storage, change in
164164
changes.append(change)
165165
}
166166

Tests/iOS/Tests/Storage/StorageObservationRegistryTests.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,40 +15,40 @@ final class StorageObservationRegistryTests: XCTestCase {
1515
)
1616
}
1717

18-
func testRegister() {
19-
registry.register { _, _ in }
18+
func testAddObservation() {
19+
registry.addObservation { _, _ in }
2020
XCTAssertEqual(registry.observations.count, 1)
2121

22-
registry.register { _, _ in }
22+
registry.addObservation { _, _ in }
2323
XCTAssertEqual(registry.observations.count, 2)
2424
}
2525

26-
func testDeregister() {
27-
let token = registry.register { _, _ in }
26+
func testRemoveObservation() {
27+
let token = registry.addObservation { _, _ in }
2828
XCTAssertEqual(registry.observations.count, 1)
2929

30-
registry.deregister(token: token)
30+
registry.removeObservation(token: token)
3131
XCTAssertTrue(registry.observations.isEmpty)
3232
}
3333

34-
func testDeregisterAll() {
35-
registry.register { _, _ in }
36-
registry.register { _, _ in }
34+
func testRemoveAllObservation() {
35+
registry.addObservation { _, _ in }
36+
registry.addObservation { _, _ in }
3737
XCTAssertEqual(registry.observations.count, 2)
3838

39-
registry.deregisterAll()
39+
registry.removeAllObservations()
4040
XCTAssertTrue(registry.observations.isEmpty)
4141
}
4242

4343
func testNotifyObservers() {
4444
var change1: StorageChange?
4545
var change2: StorageChange?
4646

47-
registry.register { _, change in
47+
registry.addObservation { _, change in
4848
change1 = change
4949
}
5050

51-
registry.register { _, change in
51+
registry.addObservation { _, change in
5252
change2 = change
5353
}
5454

Tests/iOS/Tests/Storage/StorageTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ final class StorageTests: XCTestCase {
9797
XCTAssertEqual(cachedObject.firstName, "John")
9898
}
9999

100-
func testRegisterObservations() throws {
100+
func testAddObservations() throws {
101101
var changes = [StorageChange]()
102102

103-
storage.registry.register { storage, change in
103+
storage.storageObservationRegistry.addObservation { storage, change in
104104
changes.append(change)
105105
}
106106

0 commit comments

Comments
 (0)