Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ECO-5168] Rename subscribeToDiscontinuities to onDiscontinuity #183

Merged
merged 1 commit into from
Dec 5, 2024

Conversation

lawrence-forooghian
Copy link
Collaborator

@lawrence-forooghian lawrence-forooghian commented Dec 5, 2024

I remember that when I wrote the public API in 20e7f5f, I was a bit reluctant to copy JS’s on* naming, because that read to me more like an API that was designed for receiving a listener (i.e. “on this event, call this listener”). But, I think that after some back and forth with Andy, we decided to stick to the on* naming, hence onStatusChange. For some reason, though, I didn’t apply this decision to subscribeToDiscontinuties. So, do that.

Resolves #173.

Summary by CodeRabbit

  • New Features

    • Updated method names across various components for better clarity, changing subscribeToDiscontinuities to onDiscontinuity.
  • Bug Fixes

    • Enhanced error handling in presence operations and typing events, ensuring more robust management of subscription events.
  • Documentation

    • Updated comments and documentation to reflect the new method names and clarify functionality.
  • Tests

    • Adjusted test cases to align with the renamed methods, ensuring continued verification of functionality.

I remember that when I wrote the public API in 20e7f5f, I was a bit
reluctant to copy JS’s `on*` naming, because that read to me more like
an API that was designed for receiving a listener (i.e. “_on_ this
event, call this listener”). But, I think that after some back and forth
with Andy, we decided to stick to the `on*` naming, hence
`onStatusChange`. For some reason, though, I didn’t apply this decision
to `subscribeToDiscontinuties`. So, do that.

Resolves #173.
Copy link

coderabbitai bot commented Dec 5, 2024

Walkthrough

The changes in this pull request primarily involve renaming the method subscribeToDiscontinuities to onDiscontinuity across various classes and protocols in the AblyChat project. This renaming is applied consistently to ensure alignment with JavaScript naming conventions. The internal logic and functionality of these methods remain unchanged, and additional modifications include enhancements to error handling and the introduction of the @MainActor attribute in some classes to address concurrency issues.

Changes

File Path Change Summary
Example/AblyChatExample/Mocks/MockClients.swift Renamed subscribeToDiscontinuities to onDiscontinuity in multiple mock actors.
Sources/AblyChat/DefaultMessages.swift Renamed subscribeToDiscontinuities to onDiscontinuity.
Sources/AblyChat/DefaultOccupancy.swift Renamed subscribeToDiscontinuities to onDiscontinuity.
Sources/AblyChat/DefaultPresence.swift Renamed subscribeToDiscontinuities to onDiscontinuity, added logging to several methods.
Sources/AblyChat/DefaultRoomLifecycleContributor.swift Renamed subscribeToDiscontinuities to onDiscontinuity.
Sources/AblyChat/DefaultRoomReactions.swift Renamed subscribeToDiscontinuities to onDiscontinuity, added @MainActor attribute.
Sources/AblyChat/DefaultTyping.swift Renamed subscribeToDiscontinuities to onDiscontinuity.
Sources/AblyChat/EmitsDiscontinuities.swift Renamed subscribeToDiscontinuities methods to onDiscontinuity.
Sources/AblyChat/RoomFeature.swift Renamed subscribeToDiscontinuities to onDiscontinuity in DefaultFeatureChannel.
Tests/AblyChatTests/DefaultMessagesTests.swift Renamed test method subscribeToDiscontinuities to onDiscontinuity.
Tests/AblyChatTests/DefaultRoomReactionsTests.swift Renamed test method subscribeToDiscontinuities to onDiscontinuity.
Tests/AblyChatTests/Mocks/MockFeatureChannel.swift Renamed subscribeToDiscontinuities to onDiscontinuity, modified constructor for error handling.

Assessment against linked issues

Objective Addressed Explanation
Rename subscribeToDiscontinuities to onDiscontinuity to fit JS (#173, ECO-5168)

Possibly related PRs

  • [ECO-5001] Some spec alignment #156: Modifies the subscribeToDiscontinuities method in MockClients.swift and other classes to change its return type to Subscription<DiscontinuityEvent>, aligning with the method renaming in this PR.
  • [ECO-5144] Implement CHA-PR3h etc #163: Updates the subscribeToDiscontinuities method in DefaultMessages.swift to change its return type to Subscription<DiscontinuityEvent>, reflecting similar changes made in this PR.
  • Fix integration tests #177: Addresses the renaming of the latestAction property to action in the Message struct, consistent with the naming conventions established in this PR.

Suggested reviewers

  • umair-ably
  • maratal

Poem

Hop, hop, in code we play,
Renaming methods, clear as day.
From subscribe to on we leap,
In our code, harmony we keep.
With every change, a joyful cheer,
For clarity's sake, we hold dear! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (3)
Tests/AblyChatTests/Mocks/MockFeatureChannel.swift (2)

Line range hint 7-12: Fix inconsistent variable naming in initializer

There is a mismatch between the property and the initializer parameter names:

  • Property: resultOfWaitToBeAbleToPerformPresenceOperations
  • Parameter: resultOfWaitToBeAblePerformPresenceOperations (missing "To")

As a result, the property is not correctly assigned, leading to potential issues.

Apply this diff to correct the parameter name and ensure proper assignment:

 init(
     channel: RealtimeChannelProtocol,
-    resultOfWaitToBeAblePerformPresenceOperations: Result<Void, ARTErrorInfo>? = nil
+    resultOfWaitToBeAbleToPerformPresenceOperations: Result<Void, ARTErrorInfo>? = nil
 ) {
     self.channel = channel
-    resultOfWaitToBeAblePerformPresenceOperations = resultOfWaitToBeAblePerformPresenceOperations
+    self.resultOfWaitToBeAbleToPerformPresenceOperations = resultOfWaitToBeAbleToPerformPresenceOperations
 }

Line range hint 25-27: Correct variable name in error message

In the waitToBeAbleToPerformPresenceOperations method, the fatalError message refers to resultOfWaitToBeAblePerformPresenceOperations (missing "To"), which is inconsistent with the property name resultOfWaitToBeAbleToPerformPresenceOperations. This could cause confusion during debugging.

Apply this diff to update the error message:

     guard let resultOfWaitToBeAbleToPerformPresenceOperations else {
-        fatalError("resultOfWaitToBeAblePerformPresenceOperations must be set before waitToBeAbleToPerformPresenceOperations is called")
+        fatalError("resultOfWaitToBeAbleToPerformPresenceOperations must be set before waitToBeAbleToPerformPresenceOperations is called")
     }
Sources/AblyChat/DefaultRoomReactions.swift (1)

Line range hint 3-3: Consider tracking the @mainactor requirement separately.

The TODO comment suggests this is a temporary fix for task isolation. Consider creating a separate issue to properly address the underlying concurrency concern.

Would you like me to create a GitHub issue to track the proper implementation of task isolation?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d6adda5 and 61f7793.

📒 Files selected for processing (12)
  • Example/AblyChatExample/Mocks/MockClients.swift (5 hunks)
  • Sources/AblyChat/DefaultMessages.swift (1 hunks)
  • Sources/AblyChat/DefaultOccupancy.swift (1 hunks)
  • Sources/AblyChat/DefaultPresence.swift (1 hunks)
  • Sources/AblyChat/DefaultRoomLifecycleContributor.swift (1 hunks)
  • Sources/AblyChat/DefaultRoomReactions.swift (1 hunks)
  • Sources/AblyChat/DefaultTyping.swift (1 hunks)
  • Sources/AblyChat/EmitsDiscontinuities.swift (1 hunks)
  • Sources/AblyChat/RoomFeature.swift (1 hunks)
  • Tests/AblyChatTests/DefaultMessagesTests.swift (1 hunks)
  • Tests/AblyChatTests/DefaultRoomReactionsTests.swift (1 hunks)
  • Tests/AblyChatTests/Mocks/MockFeatureChannel.swift (1 hunks)
🔇 Additional comments (12)
Sources/AblyChat/DefaultPresence.swift (1)

197-198: Renamed method to onDiscontinuity for consistency

The method subscribeToDiscontinuities has been correctly renamed to onDiscontinuity, aligning with the on* event listener naming convention used in JavaScript. This enhances consistency across the API.

Sources/AblyChat/EmitsDiscontinuities.swift (1)

13-14: Updated protocol methods to onDiscontinuity

Renaming the methods in the EmitsDiscontinuities protocol and its extension to onDiscontinuity improves clarity and aligns with the event listener naming conventions, ensuring consistency throughout the codebase.

Also applies to: 17-17, 21-22

Tests/AblyChatTests/Mocks/MockFeatureChannel.swift (1)

18-20: Renamed method to onDiscontinuity for consistency

The method subscribeToDiscontinuities has been renamed to onDiscontinuity, aligning with the on* naming convention and improving consistency with other implementations.

Sources/AblyChat/DefaultRoomLifecycleContributor.swift (1)

21-21: Method renamed to onDiscontinuity for consistency

The method subscribeToDiscontinuities has been correctly renamed to onDiscontinuity, adhering to the event listener naming convention and enhancing codebase consistency.

Sources/AblyChat/DefaultOccupancy.swift (1)

53-54: Renamed method to onDiscontinuity to align with naming conventions

The method subscribeToDiscontinuities has been appropriately renamed to onDiscontinuity, ensuring consistency with the on* event listener pattern across the API.

Tests/AblyChatTests/DefaultRoomReactionsTests.swift (1)

66-81: LGTM! Method renaming is consistent with PR objectives.

The test method has been correctly renamed from subscribeToDiscontinuities to onDiscontinuity while maintaining the same test logic and verification steps. The comments have been appropriately updated to reflect the new method name.

Tests/AblyChatTests/DefaultMessagesTests.swift (1)

74-90: LGTM! Method renaming maintains consistency across test files.

The test method has been correctly renamed from subscribeToDiscontinuities to onDiscontinuity, maintaining consistency with other test files. The test logic and verification steps remain unchanged, and comments have been appropriately updated.

Sources/AblyChat/RoomFeature.swift (1)

60-61: LGTM! Core implementation correctly renamed.

The method has been properly renamed from subscribeToDiscontinuities to onDiscontinuity in the DefaultFeatureChannel implementation, maintaining consistency with the test files and aligning with JavaScript naming conventions.

Let's verify that all usages of the old method name have been updated:

✅ Verification successful

All instances of the method have been properly renamed

The verification shows that:

  • No instances of the old method name subscribeToDiscontinuities remain in the codebase
  • The new method name onDiscontinuity is consistently used across all relevant files:
    • Core implementation files (RoomFeature.swift, DefaultMessages.swift, etc.)
    • Protocol definition (EmitsDiscontinuities.swift)
    • Test files (DefaultRoomReactionsTests.swift, DefaultMessagesTests.swift)
    • Mock implementations (MockFeatureChannel.swift, MockClients.swift)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify no remaining instances of old method name
# and confirm consistent usage of new method name

echo "Checking for any remaining instances of old method name..."
rg "subscribeToDiscontinuities"

echo "Verifying consistent usage of new method name..."
rg "onDiscontinuity" -A 2

Length of output: 8439

Sources/AblyChat/DefaultRoomReactions.swift (1)

83-84: LGTM! Method renamed as per convention.

The renaming from subscribeToDiscontinuities to onDiscontinuity aligns with JavaScript event listener naming conventions.

Sources/AblyChat/DefaultTyping.swift (1)

163-164: LGTM! Method renamed consistently.

The renaming from subscribeToDiscontinuities to onDiscontinuity maintains consistency with the new naming convention.

Example/AblyChatExample/Mocks/MockClients.swift (1)

147-147: LGTM! Methods renamed consistently across mock classes.

The renaming from subscribeToDiscontinuities to onDiscontinuity has been applied consistently across all mock implementations.

Also applies to: 198-198, 247-247, 351-351, 386-386

Sources/AblyChat/DefaultMessages.swift (1)

112-113: LGTM! Method renaming aligns with JavaScript conventions.

The renaming from subscribeToDiscontinuities to onDiscontinuity maintains functionality while improving API consistency by following the on* event listener pattern common in JavaScript.

Let's verify the consistency of this renaming across the codebase:

✅ Verification successful

Method renaming has been consistently applied across the codebase

The verification confirms that:

  • No instances of the old method name subscribeToDiscontinuities remain in the codebase
  • The new method name onDiscontinuity is consistently used across all relevant files:
    • Protocol definition in EmitsDiscontinuities.swift
    • Implementations in feature classes (DefaultMessages, DefaultTyping, DefaultPresence, etc.)
    • Test files and mocks
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all occurrences of the old method name have been renamed
# and the new name is used consistently across the codebase.

echo "Checking for any remaining instances of old method name..."
rg "subscribeToDiscontinuities"

echo "Verifying consistent usage of new method name..."
rg "onDiscontinuity" -A 2

Length of output: 8439

@lawrence-forooghian lawrence-forooghian merged commit bc1f56c into main Dec 5, 2024
12 checks passed
@lawrence-forooghian lawrence-forooghian deleted the 173-rename-subscribeToDiscontinuities branch December 5, 2024 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Rename subscribeToDiscontinuities to onDiscontinuity to fit JS
2 participants