Skip to content

Commit 2ca853f

Browse files
committed
Update liveobjects example to use latest LiveObjects changes from ably-js
Local ably-js-liveobjects build is based on the next PR [1] [1] ably/ably-js#1985
1 parent 25a22c1 commit 2ca853f

File tree

8 files changed

+44
-46
lines changed

8 files changed

+44
-46
lines changed

examples/ably-2.5.0-liveobjects.tgz

237 KB
Binary file not shown.

examples/liveobjects-live-counter/javascript/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ LiveCounters are implemented using [Ably LiveObjects](https://ably.com/docs/live
1212

1313
Use the following methods to interact with a LiveCounter in your application:
1414

15-
* [`liveObjects.getRoot()`](https://ably.com/docs/liveobjects) - retrieves the root object that serves as the starting point for storing and organizing LiveObjects state.
16-
* [`liveObjects.createCounter()`](https://ably.com/docs/liveobjects) - creates a new LiveCounter instance.
15+
* [`objects.getRoot()`](https://ably.com/docs/liveobjects) - retrieves the root object that serves as the starting point for storing and organizing objects on a channel.
16+
* [`objects.createCounter()`](https://ably.com/docs/liveobjects) - creates a new LiveCounter instance.
1717
* [`liveCounter.value()`](https://ably.com/docs/liveobjects/livecounter) - returns the current value of a counter.
1818
* [`liveCounter.increment()`](https://ably.com/docs/liveobjects/livecounter) - sends the operation message to the Ably system to increase the counter value.
1919
* [`liveCounter.decrement()`](https://ably.com/docs/liveobjects/livecounter) - sends the operation message to the Ably system to decrease the counter value.
2020
* [`liveCounter.subscribe()`](https://ably.com/docs/liveobjects/livecounter) - subscribes to LiveCounter updates by registering a listener.
2121

22-
Find out more about [LiveCounters](https://ably.com/docs/liveobjects/livecounter).
22+
Find out more about [LiveCounter](https://ably.com/docs/liveobjects/livecounter).
2323

2424
## Getting started
2525

examples/liveobjects-live-counter/javascript/src/ably.config.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { LiveCounter } from 'ably';
22
import { Color } from './script';
33

44
declare global {
5-
export interface LiveObjectsTypes {
5+
export interface ObjectsTypes {
66
root: {
77
[Color.red]: LiveCounter;
88
[Color.green]: LiveCounter;

examples/liveobjects-live-counter/javascript/src/script.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { DefaultRoot, LiveCounter, LiveMap, Realtime } from 'ably';
2-
import LiveObjects from 'ably/liveobjects';
2+
import Objects from 'ably/objects';
33
import { nanoid } from 'nanoid';
44
import './styles.css';
55

@@ -13,12 +13,12 @@ const client = new Realtime({
1313
clientId: nanoid(),
1414
key: import.meta.env.VITE_PUBLIC_ABLY_KEY as string,
1515
environment: 'sandbox',
16-
plugins: { LiveObjects },
16+
plugins: { Objects },
1717
});
1818

1919
const urlParams = new URLSearchParams(window.location.search);
2020

21-
const channelName = urlParams.get('name') || 'liveobjects-live-counter';
21+
const channelName = urlParams.get('name') || 'objects-live-counter';
2222
const channel = client.channels.get(channelName, { modes: ['STATE_PUBLISH', 'STATE_SUBSCRIBE'] });
2323

2424
const colorCountDivs: Record<Color, HTMLElement> = {
@@ -31,8 +31,8 @@ const countersReset = document.getElementById('reset');
3131
async function main() {
3232
await channel.attach();
3333

34-
const liveObjects = channel.liveObjects;
35-
const root = await liveObjects.getRoot();
34+
const objects = channel.objects;
35+
const root = await objects.getRoot();
3636

3737
await initCounters(root);
3838
addEventListenersToButtons(root);
@@ -62,7 +62,7 @@ async function initCounters(root: LiveMap<DefaultRoot>) {
6262
return;
6363
}
6464

65-
await root.set(color, await channel.liveObjects.createCounter());
65+
await root.set(color, await channel.objects.createCounter());
6666
}),
6767
);
6868
}
@@ -83,7 +83,7 @@ function addEventListenersToButtons(root: LiveMap<DefaultRoot>) {
8383
});
8484

8585
countersReset.addEventListener('click', () => {
86-
Object.values(Color).forEach(async (color) => root.set(color, await channel.liveObjects.createCounter()));
86+
Object.values(Color).forEach(async (color) => root.set(color, await channel.objects.createCounter()));
8787
});
8888
}
8989

examples/liveobjects-live-map/javascript/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Enable clients to update and synchronize key/value data across in an application in realtime.
44

5-
LiveMap provides a simple way to manage shared key/value state in realtime applications. It allows you to store primitive values and other Live Objects, enabling a composable state.
5+
LiveMap provides a simple way to manage shared key/value state in realtime applications. It allows you to store primitive values and other objects, enabling a composable state.
66

77
LiveMaps can be used to store both predefined and dynamic datasets that need to be updated in realtime. They are ideal for scenarios such as collaborative task management, live leaderboards, multiplayer game state, shared settings, or live dashboards.
88

@@ -12,14 +12,14 @@ LiveMaps are implemented using [Ably LiveObjects](https://ably.com/docs/liveobje
1212

1313
Use the following methods to interact with a LiveMap in your application:
1414

15-
* [`liveObjects.getRoot()`](https://ably.com/docs/liveobjects) - retrieves the root object that serves as the starting point for storing and organizing LiveObjects state.
16-
* [`liveObjects.createMap()`](https://ably.com/docs/liveobjects) - creates a new LiveMap instance.
15+
* [`objects.getRoot()`](https://ably.com/docs/liveobjects) - retrieves the root object that serves as the starting point for storing and organizing objects on a channel.
16+
* [`objects.createMap()`](https://ably.com/docs/liveobjects) - creates a new LiveMap instance.
1717
* [`liveMap.get(key)`](https://ably.com/docs/liveobjects/livemap) - returns the current value associated with a given key in the map.
1818
* [`liveMap.set(key, value)`](https://ably.com/docs/liveobjects/livemap) - sends the operation message to the Ably system to assign a value to a key in the map.
1919
* [`liveMap.remove(key)`](https://ably.com/docs/liveobjects/livemap) - sends the operation message to the Ably system to remove a key from the map.
2020
* [`liveMap.subscribe()`](https://ably.com/docs/liveobjects/livemap) - subscribes to LiveMap updates by registering a listener.
2121

22-
Find out more about [LiveMaps](https://ably.com/docs/liveobjects/livemap).
22+
Find out more about [LiveMap](https://ably.com/docs/liveobjects/livemap).
2323

2424
## Getting started
2525

examples/liveobjects-live-map/javascript/src/ably.config.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { LiveMap } from 'ably';
33
export type Tasks = LiveMap<{ [key: string]: string }>;
44

55
declare global {
6-
export interface LiveObjectsTypes {
6+
export interface ObjectsTypes {
77
root: {
88
tasks: Tasks;
99
};

examples/liveobjects-live-map/javascript/src/script.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { DefaultRoot, LiveMap, Realtime } from 'ably';
2-
import LiveObjects from 'ably/liveobjects';
2+
import Objects from 'ably/objects';
33
import { nanoid } from 'nanoid';
44
import { Tasks } from './ably.config';
55
import './styles.css';
@@ -8,13 +8,13 @@ const client = new Realtime({
88
clientId: nanoid(),
99
key: import.meta.env.VITE_PUBLIC_ABLY_KEY as string,
1010
environment: 'sandbox',
11-
plugins: { LiveObjects },
11+
plugins: { Objects },
1212
});
1313

1414
const urlParams = new URLSearchParams(window.location.search);
1515

16-
const channelName = urlParams.get('name') || 'liveobjects-live-map';
17-
const channel = client.channels.get(channelName, { modes: ['STATE_PUBLISH', 'STATE_SUBSCRIBE'] });
16+
const channelName = urlParams.get('name') || 'objects-live-map';
17+
const channel = client.channels.get(channelName, { modes: ['OBJECT_PUBLISH', 'OBJECT_SUBSCRIBE'] });
1818

1919
const taskInput = document.getElementById('task-input') as HTMLInputElement;
2020
const addTaskButton = document.getElementById('add-task');
@@ -24,8 +24,8 @@ const removeAllTasksDiv = document.getElementById('remove-tasks');
2424
async function main() {
2525
await channel.attach();
2626

27-
const liveObjects = channel.liveObjects;
28-
const root = await liveObjects.getRoot();
27+
const objects = channel.objects;
28+
const root = await objects.getRoot();
2929

3030
await initTasks(root);
3131
addEventListenersToButtons(root);
@@ -45,7 +45,7 @@ async function initTasks(root: LiveMap<DefaultRoot>) {
4545
return;
4646
}
4747

48-
await root.set('tasks', await channel.liveObjects.createMap());
48+
await root.set('tasks', await channel.objects.createMap());
4949
}
5050

5151
function subscribeToTasksUpdates(tasks: Tasks) {
@@ -122,7 +122,7 @@ function addEventListenersToButtons(root: LiveMap<DefaultRoot>) {
122122
});
123123

124124
removeAllTasksDiv.addEventListener('click', async () => {
125-
await root.set('tasks', await channel.liveObjects.createMap());
125+
await root.set('tasks', await channel.objects.createMap());
126126
});
127127
}
128128

examples/yarn.lock

+20-22
Original file line numberDiff line numberDiff line change
@@ -944,18 +944,7 @@
944944

945945
"ably@file:./ably-2.5.0-liveobjects.tgz":
946946
version "2.5.0"
947-
resolved "file:./ably-2.5.0-liveobjects.tgz#58d547974185dd396842d6f4cbc67e1ac90b8100"
948-
dependencies:
949-
"@ably/msgpack-js" "^0.4.0"
950-
deep-equal "^2.2.3"
951-
fastestsmallesttextencoderdecoder "^1.0.22"
952-
got "^11.8.5"
953-
ulid "^2.3.0"
954-
ws "^8.17.1"
955-
956-
"ably@file:./liveobjects-live-counter/javascript/ably-2.5.0-liveobjects.tgz":
957-
version "2.5.0"
958-
resolved "file:./liveobjects-live-counter/javascript/ably-2.5.0-liveobjects.tgz#4638e4ee033acfe1dba7d4227ab8c0df08dfb81e"
947+
resolved "file:./ably-2.5.0-liveobjects.tgz#4638e4ee033acfe1dba7d4227ab8c0df08dfb81e"
959948
dependencies:
960949
"@ably/msgpack-js" "^0.4.0"
961950
deep-equal "^2.2.3"
@@ -3962,8 +3951,16 @@ streamsearch@^1.1.0:
39623951
resolved "https://registry.yarnpkg.com/streamsearch/-/streamsearch-1.1.0.tgz#404dd1e2247ca94af554e841a8ef0eaa238da764"
39633952
integrity sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==
39643953

3965-
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0:
3966-
name string-width-cjs
3954+
"string-width-cjs@npm:string-width@^4.2.0":
3955+
version "4.2.3"
3956+
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
3957+
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
3958+
dependencies:
3959+
emoji-regex "^8.0.0"
3960+
is-fullwidth-code-point "^3.0.0"
3961+
strip-ansi "^6.0.1"
3962+
3963+
string-width@^4.1.0:
39673964
version "4.2.3"
39683965
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
39693966
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -4049,8 +4046,14 @@ string.prototype.trimstart@^1.0.8:
40494046
define-properties "^1.2.1"
40504047
es-object-atoms "^1.0.0"
40514048

4052-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
4053-
name strip-ansi-cjs
4049+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
4050+
version "6.0.1"
4051+
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
4052+
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
4053+
dependencies:
4054+
ansi-regex "^5.0.1"
4055+
4056+
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
40544057
version "6.0.1"
40554058
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
40564059
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -4111,7 +4114,7 @@ [email protected]:
41114114
resolved "https://registry.yarnpkg.com/tailwindcss/-/tailwindcss-4.0.14.tgz#531548524eb422fb8b89a24ebdf267c6726a09c6"
41124115
integrity sha512-92YT2dpt671tFiHH/e1ok9D987N9fHD5VWoly1CdPD/Cd1HMglvZwP3nx2yTj2lbXDAHt8QssZkxTLCCTNL+xw==
41134116

4114-
tailwindcss@^3.4.1, tailwindcss@^3.4.13:
4117+
tailwindcss@^3.4.1:
41154118
version "3.4.17"
41164119
resolved "https://registry.yarnpkg.com/tailwindcss/-/tailwindcss-3.4.17.tgz#ae8406c0f96696a631c790768ff319d46d5e5a63"
41174120
integrity sha512-w33E2aCvSDP0tW9RZuNXadXlkHXqFzSkQew/aIa2i/Sj8fThxwovwlXHSPXTbAHwEIhBFXAedUhP2tueAKP8Og==
@@ -4294,11 +4297,6 @@ typescript@^5:
42944297
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.7.3.tgz#919b44a7dbb8583a9b856d162be24a54bf80073e"
42954298
integrity sha512-84MVSjMEHP+FQRPy3pX9sTVV/INIex71s9TL2Gm5FG/WG1SqXeKyZ0k7/blY/4FdOzI12CBy1vGc4og/eus0fw==
42964299

4297-
typescript@^5.6.3:
4298-
version "5.8.2"
4299-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.8.2.tgz#8170b3702f74b79db2e5a96207c15e65807999e4"
4300-
integrity sha512-aJn6wq13/afZp/jT9QZmwEjDqqvSGp1VT5GVg+f/t6/oVyrgXM6BY1h9BRh/O5p3PlUPAe+WuiEZOmb/49RqoQ==
4301-
43024300
uikit@^3.7.0:
43034301
version "3.23.1"
43044302
resolved "https://registry.yarnpkg.com/uikit/-/uikit-3.23.1.tgz#38c2d8b5e2ab5d2e5433ba3831320192c7c0ee5e"

0 commit comments

Comments
 (0)