Skip to content

Commit 1c901a8

Browse files
Always transition to SYNCING on receipt of ATTACHED
This copies the change added in the referenced JS commit.
1 parent fba49ef commit 1c901a8

4 files changed

Lines changed: 11 additions & 10 deletions

File tree

Sources/AblyLiveObjects/Internal/InternalDefaultRealtimeObjects.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ internal final class InternalDefaultRealtimeObjects: Sendable, LiveMapObjectsPoo
448448

449449
/// The state that drives the emission of the `syncing` and `synced` events and which stores the sync sequence data.
450450
///
451-
/// This manipulation of this value is based on https://github.com/ably/ably-js/blob/0c5baa9273ca87aec6ca594833d59c4c4d2dddbb/src/plugins/objects/objects.ts.
451+
/// This manipulation of this value is based on https://github.com/ably/ably-js/blob/e280bff11a4a7627362c5185e764b7ebd0490570/src/plugins/objects/objects.ts.
452452
/// TODO: Bring in line with spec once it exists (https://github.com/ably/ably-liveobjects-swift-plugin/issues/80)
453453
internal var state = State.initialized
454454

@@ -507,8 +507,8 @@ internal final class InternalDefaultRealtimeObjects: Sendable, LiveMapObjectsPoo
507507

508508
onChannelAttachedHasObjects = hasObjects
509509

510-
if (hasObjects && state.toObjectsSyncState != .syncing) || state.toObjectsSyncState == .initialized {
511-
// We will subsequently transition to .synced either by the completion of the RTO4a OBJECT_SYNC, or by the RTO4b no-HAS_OBJECTS case below
510+
// We will subsequently transition to .synced either by the completion of the RTO4a OBJECT_SYNC, or by the RTO4b no-HAS_OBJECTS case below
511+
if state.toObjectsSyncState != .syncing {
512512
transition(to: .syncing(.init(syncSequence: nil)), userCallbackQueue: userCallbackQueue)
513513
}
514514

@@ -523,9 +523,7 @@ internal final class InternalDefaultRealtimeObjects: Sendable, LiveMapObjectsPoo
523523
// I have, for now, not directly implemented the "perform the actions for object sync completion" of RTO4b4 since my implementation doesn't quite match the model given there; here you only have a SyncObjectsPool if you have an OBJECT_SYNC in progress, which you might not have upon receiving an ATTACHED. Instead I've just implemented what seem like the relevant side effects. Can revisit this if "the actions for object sync completion" get more complex.
524524

525525
// RTO4b3, RTO4b4, RTO4b5, RTO5c3, RTO5c4, RTO5c5
526-
if state.toObjectsSyncState != .synced {
527-
transition(to: .synced, userCallbackQueue: userCallbackQueue)
528-
}
526+
transition(to: .synced, userCallbackQueue: userCallbackQueue)
529527
}
530528

531529
/// Implements the `OBJECT_SYNC` handling of RTO5.

Sources/AblyLiveObjects/Internal/InternalLiveObject.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ internal extension InternalLiveObject {
3535
resetDataToZeroValued()
3636

3737
// Emit the deleted lifecycle event
38-
// Taken from https://github.com/ably/ably-js/blob/0c5baa9273ca87aec6ca594833d59c4c4d2dddbb/src/plugins/objects/liveobject.ts#L168
38+
// Taken from https://github.com/ably/ably-js/blob/e280bff11a4a7627362c5185e764b7ebd0490570/src/plugins/objects/liveobject.ts#L168
3939
// TODO: Bring in line with spec once it exists (https://github.com/ably/ably-liveobjects-swift-plugin/issues/77)
4040
liveObjectMutableState.emitLifecycleEvent(.deleted, on: userCallbackQueue)
4141
}

Sources/AblyLiveObjects/Internal/ObjectsSyncState.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// The type that the spec uses to represent the client's state of syncing its local Objects data with the server.
22
///
3-
/// (TODO: This isn't actually in the spec yet, will specify in https://github.com/ably/ably-liveobjects-swift-plugin/issues/80; it's currently copied from https://github.com/ably/ably-js/blob/0c5baa9273ca87aec6ca594833d59c4c4d2dddbb/src/plugins/objects/objects.ts)
3+
/// (TODO: This isn't actually in the spec yet, will specify in https://github.com/ably/ably-liveobjects-swift-plugin/issues/80; it's currently copied from https://github.com/ably/ably-js/blob/e280bff11a4a7627362c5185e764b7ebd0490570/src/plugins/objects/objects.ts)
44
internal enum ObjectsSyncState {
55
case initialized
66
case syncing

Tests/AblyLiveObjectsTests/InternalDefaultRealtimeObjectsTests.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,9 +1475,12 @@ struct InternalDefaultRealtimeObjectsTests {
14751475
),
14761476
14771477
.init(
1478-
description: "ATTACHED with HAS_OBJECTS false once SYNCED should not provoke further events",
1478+
description: "ATTACHED with HAS_OBJECTS false once SYNCED emits SYNCING and then SYNCED",
14791479
channelEvents: [.attached(hasObjects: false), .attached(hasObjects: false)],
1480-
expectedSyncEvents: [.syncing, .synced],
1480+
expectedSyncEvents: [
1481+
.syncing, .synced, // The initial SYNCED
1482+
.syncing, .synced, // From the subsequent ATTACHED
1483+
],
14811484
),
14821485
14831486
.init(

0 commit comments

Comments
 (0)