Skip to content

Commit

Permalink
chore: add readonly access to CallbackManager properties
Browse files Browse the repository at this point in the history
  • Loading branch information
grdsdev committed Apr 8, 2024
1 parent 2de8a7e commit de6256e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 8 additions & 0 deletions Sources/Realtime/V2/CallbackManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ final class CallbackManager: @unchecked Sendable {

private let mutableState = LockIsolated(MutableState())

var serverChanges: [PostgresJoinConfig] {
mutableState.serverChanges
}

var callbacks: [RealtimeCallback] {
mutableState.callbacks
}

@discardableResult
func addBroadcastCallback(
event: String,
Expand Down
8 changes: 4 additions & 4 deletions Tests/RealtimeTests/CallbackManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ final class CallbackManagerTests: XCTestCase {

XCTAssertEqual(callbackManager.addPresenceCallback { _ in }, 3)

XCTAssertEqual(callbackManager.mutableState.value.callbacks.count, 3)
XCTAssertEqual(callbackManager.callbacks.count, 3)

callbackManager.removeCallback(id: 2)
callbackManager.removeCallback(id: 3)

XCTAssertEqual(callbackManager.mutableState.value.callbacks.count, 1)
XCTAssertEqual(callbackManager.callbacks.count, 1)
XCTAssertFalse(
callbackManager.mutableState.value.callbacks
callbackManager.callbacks
.contains(where: { $0.id == 2 || $0.id == 3 })
)
}
Expand All @@ -62,7 +62,7 @@ final class CallbackManagerTests: XCTestCase {

callbackManager.setServerChanges(changes: changes)

XCTAssertEqual(callbackManager.mutableState.value.serverChanges, changes)
XCTAssertEqual(callbackManager.serverChanges, changes)
}

func testTriggerPostgresChanges() {
Expand Down

0 comments on commit de6256e

Please sign in to comment.