Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/data/languages/languageData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default {
liveObjects: {
javascript: '2.21',
swift: '0.4',
java: '1.7',
java: '1.8',
},
liveSync: {
javascript: '0.4',
Expand Down
5 changes: 4 additions & 1 deletion src/data/nav/liveobjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export default {
{
name: 'Batch operations',
link: '/docs/liveobjects/batch',
languages: ['javascript', 'swift', 'java'],
},
{
name: 'Lifecycle events',
Expand All @@ -97,6 +98,7 @@ export default {
{
name: 'Object storage',
link: '/docs/liveobjects/storage',
languages: ['javascript', 'swift', 'java'],
},
{
name: 'Using the REST SDK',
Expand Down Expand Up @@ -128,7 +130,8 @@ export default {
external: true,
},
{
link: 'https://sdk.ably.com/builds/ably/ably-java/main/javadoc/io/ably/lib/objects/RealtimeObjects.html',
// TODO: verify this URL resolves once the path-based API javadoc is published
link: 'https://sdk.ably.com/builds/ably/ably-java/main/javadoc/io/ably/lib/liveobjects/RealtimeObject.html',
Comment thread
coderabbitai[bot] marked this conversation as resolved.
name: 'Java SDK',
external: true,
},
Expand Down
6 changes: 3 additions & 3 deletions src/pages/docs/api/realtime-sdk/channels.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ Provides access to the [`RealtimeAnnotations`](#realtime-annotations) object for

</If>

<If lang="javascript">
<If lang="javascript,java">
#### object <a id="object" />

Provides access to the [RealtimeObject](/docs/liveobjects) for this channel which can be used to read, modify and subscribe to LiveObjects on a channel.
<If lang="javascript">Provides access to the [RealtimeObject](/docs/liveobjects) for this channel which can be used to read, modify and subscribe to LiveObjects on a channel.</If><If lang="java">A public field providing access to the [RealtimeObject](/docs/liveobjects) for this channel, which can be used to read, modify and subscribe to LiveObjects on a channel.</If>
</If>

<If lang="swift,java">
<If lang="swift">
#### objects <a id="objects" />

Provides access to the [Objects](/docs/liveobjects) object for this channel which can be used to read, modify and subscribe to LiveObjects on a channel.
Expand Down
48 changes: 30 additions & 18 deletions src/pages/docs/liveobjects/batch.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,19 @@ meta_description: "Group multiple objects operations into a single channel messa
</Aside>
</If>

<If lang="swift">
<Aside data-type="note">
Batch operations are only currently only supported in LiveObjects JavaScript. Support for Swift and Java is coming soon.
Batch operations are not yet supported in LiveObjects Swift; support is coming soon.
</Aside>
</If>

<If lang="java">
<Aside data-type="note">
Batch operations are not yet supported in the Java SDK. Each mutation (`set`, `remove`, `increment`, `decrement`) publishes as its own message and is individually atomic. See the [LiveMap](/docs/liveobjects/map?lang=java) and [LiveCounter](/docs/liveobjects/counter?lang=java) documentation for the single-operation methods. To apply multiple operations atomically, use [batch operations via the LiveObjects REST API](/docs/liveobjects/rest-api-usage#batch-operations) instead.
</Aside>
</If>

<If lang="javascript">

Batch operations allow multiple updates to be grouped into a single channel message and applied atomically. It ensures that all operations in a batch either succeed together or are discarded entirely. Batching is essential when multiple related updates to channel objects must be applied as a single atomic unit, for example, when application logic depends on multiple objects being updated simultaneously. Batching ensures that all operations in the batch either succeed or fail together.

Expand All @@ -41,24 +51,24 @@ Call `batch()` on a `PathObject` to group operations on that path:

<Code>
```javascript
const myObject = await channel.object.get();
const rootObject = await channel.object.get();

// Batch multiple operations on the channel object
await myObject.batch((ctx) => {
await rootObject.batch((ctx) => {
ctx.set('foo', 'bar');
ctx.set('baz', 42);
ctx.remove('oldKey');
});

// Batch operations on a nested path
await myObject.get('settings').batch((ctx) => {
await rootObject.get('settings').batch((ctx) => {
ctx.set('theme', 'dark');
ctx.set('fontSize', 14);
ctx.set('notifications', true);
});

// Batch operations on a counter
await myObject.get('visits').batch((ctx) => {
await rootObject.get('visits').batch((ctx) => {
ctx.increment(5);
ctx.increment(3);
ctx.decrement(2);
Expand All @@ -74,11 +84,11 @@ You can only call `batch()` on an `PathObject` whose path resolves to a `LiveMap

<Code>
```javascript
const myObject = await channel.object.get();
const rootObject = await channel.object.get();

try {
// Call batch() on 'username', which resolves to a string value
await myObject.get('username').batch((ctx) => {});
await rootObject.get('username').batch((ctx) => {});
} catch (err) {
// Error 92007: Cannot batch operations on a non-LiveObject at path: username
}
Expand All @@ -89,7 +99,7 @@ You can also call `batch()` on an `Instance` to batch operations on that specifi

<Code>
```javascript
const settingsInstance = myObject.get('settings').instance();
const settingsInstance = rootObject.get('settings').instance();

if (settingsInstance) {
await settingsInstance.batch((ctx) => {
Expand All @@ -107,9 +117,9 @@ You can create new objects inside a batch using `LiveMap.create()` and `LiveCoun

<Code>
```javascript
const myObject = await channel.object.get();
const rootObject = await channel.object.get();

await myObject.batch((ctx) => {
await rootObject.batch((ctx) => {
// Create and assign multiple objects atomically
ctx.set('user', LiveMap.create({
name: 'Alice',
Expand Down Expand Up @@ -137,7 +147,7 @@ Navigate to nested objects using the `get()` method on the batch context. Naviga

<Code>
```javascript
await myObject.batch((ctx) => {
await rootObject.batch((ctx) => {
// Navigate to nested paths and perform operations
ctx.get('settings')?.set('theme', 'dark');
ctx.get('settings')?.get('preferences')?.set('language', 'en');
Expand All @@ -156,7 +166,7 @@ To explicitly cancel a batch before it is applied, throw an error inside the bat
<Code>
```javascript
try {
await myObject.batch((ctx) => {
await rootObject.batch((ctx) => {
// Cancel the entire batch if a required value is missing
const value = ctx.get('visits')?.value();
if (value === undefined) {
Expand All @@ -183,7 +193,7 @@ The batch callback function must be synchronous because the batch method sends t
<Code>
```javascript
try {
await myObject.batch((ctx) => {
await rootObject.batch((ctx) => {
// These operations are synchronous and queued
ctx.get('settings')?.set('theme', 'dark');
ctx.get('visits')?.increment();
Expand All @@ -203,7 +213,7 @@ Since the batch callback is synchronous, you can read current values inside a ba

<Code>
```javascript
await myObject.batch((ctx) => {
await rootObject.batch((ctx) => {
ctx.get('settings')?.get('theme')?.value(); // "dark"
// no updates will be applied during execution of the batch callback
ctx.get('settings')?.get('theme')?.value(); // "dark"
Expand All @@ -215,7 +225,7 @@ Operations on a batch context are not applied until they are all published, so y

<Code>
```javascript
await myObject.batch((ctx) => {
await rootObject.batch((ctx) => {
// Get the value at the time batch() was called
ctx.get('settings')?.get('theme')?.value(); // "dark"

Expand All @@ -234,7 +244,7 @@ The batch context object cannot be used outside the callback function. Attemptin
<Code>
```javascript
let context;
await myObject.batch((ctx) => {
await rootObject.batch((ctx) => {
context = ctx;
ctx.set('foo', 'bar');
});
Expand All @@ -253,12 +263,12 @@ When a batch operation is applied, the subscription is notified synchronously an
<Code>
```javascript
// Subscribe to the channel object
myObject.subscribe(({ object, message }) => {
rootObject.subscribe(({ object, message }) => {
console.log("Update:", message?.operation.action, message?.operation?.mapSet?.key);
});

// Perform a batch operation
await myObject.batch((ctx) => {
await rootObject.batch((ctx) => {
ctx.set('foo', 'bar');
ctx.set('baz', 42);
ctx.set('qux', 'hello');
Expand All @@ -269,3 +279,5 @@ await myObject.batch((ctx) => {
// Update: map.set qux
```
</Code>

</If>
Loading