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

[PUB-1039] Update Live Objects README section #1969

Open
wants to merge 1 commit into
base: integration/liveobjects
Choose a base branch
from

Conversation

VeskeR
Copy link
Contributor

@VeskeR VeskeR commented Feb 13, 2025

Describe the Live Objects create/edit/read API, live object types, root object, state channel modes, batch operations lifecycle events and user provided typings for Live Objects.

Resolves PUB-1039

Summary by CodeRabbit

  • Documentation
    • Enhanced Ably client library documentation with refined guidance on push notifications and Live Objects.
    • Corrected a typographical error in the push notifications text.
    • Renamed the Live Objects section and added a new "State Channel Modes" subsection detailing channel requirements.
    • Updated example code to TypeScript, offering clearer instructions for interacting with Live Objects features such as maps and counters.

Copy link

coderabbitai bot commented Feb 13, 2025

Warning

Rate limit exceeded

@VeskeR has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 21 minutes and 24 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 344c5e9 and 54a5125.

📒 Files selected for processing (1)
  • README.md (3 hunks)

Walkthrough

The documentation in the README.md has been updated to improve clarity around the Ably client library’s Live Objects feature. A typo in "push notifications" has been corrected, and the section formerly titled "Live Objects functionality" is now simply "Live Objects." A new "State Channel Modes" subsection has been added, and the code examples have been updated from JavaScript to TypeScript. Detailed explanations, including how to initialize the client and work with LiveMap and LiveCounter, have been incorporated.

Changes

File Path Change Summary
README.md - Corrected typo in "push notifications".
- Renamed "Live Objects functionality" to "Live Objects".
- Added "State Channel Modes" subsection with channel mode details.
- Updated code snippets from JavaScript to TypeScript and refined examples for LiveMap and LiveCounter.

Possibly related PRs

Poem

In the garden of docs, I happily roam,
Hoping through guidelines to make code my home,
With a corrected typo and TypeScript in sight,
Live Objects shine clearly, so brilliantly bright,
I, a rabbit, cheer with a skip and a hop,
Enjoying these changes that never shall stop! 🐰🌸


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@VeskeR VeskeR requested review from zknill and kaschula February 13, 2025 09:28
@github-actions github-actions bot temporarily deployed to staging/pull/1969/bundle-report February 13, 2025 09:29 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1969/typedoc February 13, 2025 09:29 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1969/features February 13, 2025 09:29 Inactive
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: 0

🧹 Nitpick comments (3)
README.md (3)

626-645: Consider adding examples of required capabilities.

The State Channel Modes section clearly explains the required channel modes. However, it would be helpful to include examples of the corresponding capabilities required in the authentication token.

Add examples of required capabilities:

+```typescript
+// Example capabilities for Live Objects
+{
+  "channel": {
+    "my_live_objects_channel": ["state_subscribe", "state_publish"]
+  }
+}
+```
🧰 Tools
🪛 LanguageTool

[uncategorized] ~628-~628: Possible missing article found.
Context: ...cts). #### State Channel Modes To use Live Objects feature, clients must attach to...

(AI_HYDRA_LEO_MISSING_THE)

🪛 markdownlint-cli2 (0.17.2)

633-633: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)


707-756: Consider adding error handling examples.

The Subscribing to Updates section is well-documented, but it would be beneficial to include examples of error handling in the subscription callbacks.

Add error handling examples:

+```typescript
+// Example with error handling
+root.subscribe((update: LiveMapUpdate) => {
+  try {
+    console.log('LiveMap updated:', update);
+    // Handle the update
+  } catch (error) {
+    console.error('Error handling LiveMap update:', error);
+  }
+});
+```
🧰 Tools
🪛 LanguageTool

[uncategorized] ~708-~708: It seems likely that a singular genitive (’s) apostrophe is missing.
Context: ...ltiple clients may modify the same Live Objects state, subscribing ensures that your ap...

(AI_HYDRA_LEO_APOSTROPHE_S_XS)

🪛 markdownlint-cli2 (0.17.2)

714-714: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)


744-744: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)


785-805: Consider adding error handling for batch operations.

The Batch Operations section clearly explains batching, but should include guidance on error handling within batch callbacks.

Add error handling example:

+```typescript
+// Example with error handling
+try {
+  await liveObjects.batch((ctx) => {
+    // ... batch operations
+  });
+} catch (error) {
+  console.error('Batch operation failed:', error);
+  // Handle the error appropriately
+}
+```
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

791-791: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6fc1702 and 344c5e9.

📒 Files selected for processing (1)
  • README.md (3 hunks)
🧰 Additional context used
🪛 LanguageTool
README.md

[style] ~593-~593: Consider a shorter alternative to avoid wordiness.
Context: ...ime clients via the LiveObjects plugin. In order to use Live Objects, you must pass in the ...

(IN_ORDER_TO_PREMIUM)


[uncategorized] ~628-~628: Possible missing article found.
Context: ...cts). #### State Channel Modes To use Live Objects feature, clients must attach to...

(AI_HYDRA_LEO_MISSING_THE)


[style] ~648-~648: Consider a shorter alternative to avoid wordiness.
Context: ...d data structures and must be retrieved in order to interact with the existing state. ```t...

(IN_ORDER_TO_PREMIUM)


[uncategorized] ~708-~708: It seems likely that a singular genitive (’s) apostrophe is missing.
Context: ...ltiple clients may modify the same Live Objects state, subscribing ensures that your ap...

(AI_HYDRA_LEO_APOSTROPHE_S_XS)

🪛 markdownlint-cli2 (0.17.2)
README.md

595-595: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)


615-615: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)


633-633: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)


650-650: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)


664-664: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)


692-692: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)


714-714: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)


744-744: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)


762-762: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)


769-769: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)


791-791: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)


813-813: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)


827-827: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)


839-839: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)


858-858: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)


878-878: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)


888-888: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)

🪛 GitHub Actions: Lint
README.md

[warning] 1-1: Code style issues found in the above file. Run Prettier with --write to fix.

⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: test-node (20.x)
  • GitHub Check: test-browser (webkit)
  • GitHub Check: test-node (18.x)
  • GitHub Check: test-browser (firefox)
  • GitHub Check: test-browser (chromium)
  • GitHub Check: test-node (16.x)
  • GitHub Check: test-npm-package
🔇 Additional comments (7)
README.md (7)

587-587: LGTM!

Good addition of the link to push notifications documentation, which helps users find more detailed information.


589-624: LGTM! Well-structured introduction to Live Objects.

The introduction and plugin usage section is clear and comprehensive, providing both npm and CDN installation options with proper versioning information.

🧰 Tools
🪛 LanguageTool

[style] ~593-~593: Consider a shorter alternative to avoid wordiness.
Context: ...ime clients via the LiveObjects plugin. In order to use Live Objects, you must pass in the ...

(IN_ORDER_TO_PREMIUM)


[uncategorized] ~622-~622: Possible missing comma found.
Context: ...y.com/lib/liveobjects.umd.min-2.4.0.js. Note you can load the non-minified version b...

(AI_HYDRA_LEO_MISSING_COMMA)

🪛 markdownlint-cli2 (0.17.2)

595-595: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)


609-609: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)


615-615: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)


622-622: Bare URL used
null

(MD034, no-bare-urls)


622-622: Bare URL used
null

(MD034, no-bare-urls)


622-622: Bare URL used
null

(MD034, no-bare-urls)


622-622: Bare URL used
null

(MD034, no-bare-urls)


622-622: Spaces inside emphasis markers
null

(MD037, no-space-in-emphasis)


647-655: LGTM! Clear explanation of the root object.

The Root Object section effectively explains its role as the entry point for Live Objects state.

🧰 Tools
🪛 LanguageTool

[style] ~648-~648: Consider a shorter alternative to avoid wordiness.
Context: ...d data structures and must be retrieved in order to interact with the existing state. ```t...

(IN_ORDER_TO_PREMIUM)

🪛 markdownlint-cli2 (0.17.2)

650-650: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)


657-705: LGTM! Comprehensive coverage of Live Object Types.

The Live Object Types section provides clear explanations and examples for both LiveMap and LiveCounter types.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

664-664: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)


692-692: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)


758-783: LGTM! Clear examples of object creation and hierarchy.

The Creating New Objects section effectively demonstrates how to create and organize Live Objects in a hierarchy.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

762-762: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)


769-769: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)


807-852: LGTM! Comprehensive coverage of lifecycle events.

The Lifecycle Events section effectively explains both synchronization and deletion events with clear examples.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

813-813: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)


827-827: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)


839-839: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)


854-885: LGTM! Well-documented TypeScript support.

The Typing Live Objects section provides clear examples of both global and channel-specific type definitions.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

858-858: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)


878-878: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)

README.md Outdated

#### Live Object Types

Live Objects support two primary data structures:
Copy link
Member

Choose a reason for hiding this comment

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

currently

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated 👍

@VeskeR VeskeR force-pushed the PUB-1039/update-readme branch from 344c5e9 to cf1c49b Compare February 13, 2025 09:34
Describe the Live Objects create/edit/read API, live object types,
root object, state channel modes, batch operations lifecycle events and
user provided typings for Live Objects.

Subscribing to updates on Live Objects allows you to receive changes made by other clients in realtime. Since multiple clients may modify the same Live Objects state, subscribing ensures that your application reacts to external updates as soon as they are received.

Additionally, mutation methods such as `LiveMap.set`, `LiveCounter.increment`, and `LiveCounter.decrement` do not directly edit the current state of the object locally. Instead, they send the intended operation to the Ably system, and the change is applied to the local object only when the corresponding realtime operation is echoed back to the client. This means that the state you retrieve immediately after a mutation may not reflect the latest updates yet.
Copy link
Member

Choose a reason for hiding this comment

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

Can you clarify this? If you await a mutation, the local state does not have that mutation applied after completion of the operation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct, the mutation operation might not be applied after we await the mutation call, as this only awaits the ACK message for the mutation operation. It will be applied only once the operation is echoed back to the client.

We discussed this with Mike in this DR, and considered the possibility of applying the mutation client-side when we receive an ACK message (meaning it would be applied locally after await). It needed more thought (as we rely on applying messages from a given site in regional order), and it was put on hold for the time being.

@VeskeR VeskeR requested a review from a team February 13, 2025 13:49

The authentication token must include corresponding capabilities for the client to interact with Live Objects.

#### Obtaining the Root Object
Copy link

Choose a reason for hiding this comment

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

Obtaining is a really convoluted word. Where possible we should prefer the simplest possible language. How about "getting" or "accessing" ?


#### Obtaining the Root Object

The root object represents the top-level entry point for Live Objects state within a channel. It acts as a container for all nested data structures and must be retrieved in order to interact with the existing state.
Copy link

@zknill zknill Feb 14, 2025

Choose a reason for hiding this comment

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

Suggested change
The root object represents the top-level entry point for Live Objects state within a channel. It acts as a container for all nested data structures and must be retrieved in order to interact with the existing state.
The root object represents the top-level entry point for Live Objects state within a channel. It give access to all other nested live objects.

Copy link

@zknill zknill left a comment

Choose a reason for hiding this comment

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

Nice! A few boring re-word suggestions for simplicity/clarity 👌

const root = await liveObjects.getRoot();
```

The root object is always a `LiveMap` instance and serves as the starting point for storing and organizing Live Objects state.
Copy link

Choose a reason for hiding this comment

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

Suggested change
The root object is always a `LiveMap` instance and serves as the starting point for storing and organizing Live Objects state.
The root object is a `LiveMap` instance and serves as the starting point for storing and organizing Live Objects state.


#### Live Object Types

Live Objects currently support two primary data structures:
Copy link

Choose a reason for hiding this comment

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

Suggested change
Live Objects currently support two primary data structures:
Live Objects currently supports two primary data structures; LiveMap and LiveCounter.


Additionally, mutation methods such as `LiveMap.set`, `LiveCounter.increment`, and `LiveCounter.decrement` do not directly edit the current state of the object locally. Instead, they send the intended operation to the Ably system, and the change is applied to the local object only when the corresponding realtime operation is echoed back to the client. This means that the state you retrieve immediately after a mutation may not reflect the latest updates yet.

To ensure you react to state changes at the correct moment, you can subscribe to updates on all Live Objects as follows:
Copy link

Choose a reason for hiding this comment

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

Suggested change
To ensure you react to state changes at the correct moment, you can subscribe to updates on all Live Objects as follows:
You can subscribe to updates on all Live Objects using subscription listeners as follows:

I've added "subscription listeners" here because later way say you can de-register "subscription listeners" without mentioning them before. Obviously you can see from the code, but adding clarity here.


// perform operations on LiveMap and LiveCounter
await root.set('name', 'Alice');
// LiveMap updated: { update: { name: 'updated' } }
Copy link

Choose a reason for hiding this comment

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

question: should the update event carry the new value as well as the key that was modified?

});
```

**Object Deletion Events** - objects that have been orphaned for a long period (i.e., not connected to the state tree graph by being set as a key in a map related to the root) will eventually be deleted. Once a Live Object is deleted, it can no longer be interacted with. You should avoid accessing its data or try to update its value and should remove all references to the deleted object in your application.
Copy link

Choose a reason for hiding this comment

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

Suggested change
**Object Deletion Events** - objects that have been orphaned for a long period (i.e., not connected to the state tree graph by being set as a key in a map related to the root) will eventually be deleted. Once a Live Object is deleted, it can no longer be interacted with. You should avoid accessing its data or try to update its value and should remove all references to the deleted object in your application.
**Object Deletion Events** - objects that have been orphaned for a long period (i.e., not connected to the state tree graph by being set as a key in a map related to the root) will eventually be deleted. Once a Live Object is deleted, it can no longer be interacted with. You should avoid accessing its data or trying to update its value and you should remove all references to the deleted object in your application.

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.

3 participants