You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+56-56Lines changed: 56 additions & 56 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -588,82 +588,82 @@ For more information on publishing push notifications over Ably, see the [Ably p
588
588
589
589
### LiveObjects
590
590
591
-
#### Using the plugin
591
+
#### Using the Objects plugin
592
592
593
-
LiveObjects functionality is supported for Realtime clients via the LiveObjects plugin. In order to use LiveObjects, you must pass in the plugin via client options.
593
+
LiveObjects functionality is supported for Realtime clients via the Objects plugin. In order to use Objects on a channel, you must pass in the plugin via client options.
594
594
595
595
```typescript
596
596
import*asAblyfrom'ably';
597
-
importLiveObjectsfrom'ably/liveobjects';
597
+
importObjectsfrom'ably/objects';
598
598
599
599
constclient=newAbly.Realtime({
600
600
...options,
601
-
plugins: { LiveObjects },
601
+
plugins: { Objects },
602
602
});
603
603
```
604
604
605
-
LiveObjects plugin also works with the [Modular variant](#modular-tree-shakable-variant) of the library.
605
+
Objects plugin also works with the [Modular variant](#modular-tree-shakable-variant) of the library.
606
606
607
-
Alternatively, you can load the LiveObjects plugin directly in your HTML using `script` tag (in case you can't use a package manager):
607
+
Alternatively, you can load the Objects plugin directly in your HTML using `script` tag (in case you can't use a package manager):
When loaded this way, the LiveObjects plugin will be available on the global object via the `AblyLiveObjectsPlugin` property, so you will need to pass it to the Ably instance as follows:
613
+
When loaded this way, the Objects plugin will be available on the global object via the `AblyObjectsPlugin` property, so you will need to pass it to the Ably instance as follows:
614
614
615
615
```typescript
616
616
constclient=newAbly.Realtime({
617
617
...options,
618
-
plugins: { LiveObjects: AblyLiveObjectsPlugin },
618
+
plugins: { Objects: AblyObjectsPlugin },
619
619
});
620
620
```
621
621
622
-
The LiveObjects plugin is developed as part of the Ably client library, so it is available for the same versions as the Ably client library itself. It also means that it follows the same semantic versioning rules as they were defined for [the Ably client library](#for-browsers). For example, to lock into a major or minor version of the LiveObjects plugin, you can specify a specific version number such as https://cdn.ably.com/lib/liveobjects.umd.min-2.js for all v2._ versions, or https://cdn.ably.com/lib/liveobjects.umd.min-2.4.js for all v2.4._ versions, or you can lock into a single release with https://cdn.ably.com/lib/liveobjects.umd.min-2.4.0.js. Note you can load the non-minified version by omitting `.min` from the URL such as https://cdn.ably.com/lib/liveobjects.umd-2.js.
622
+
The Objects plugin is developed as part of the Ably client library, so it is available for the same versions as the Ably client library itself. It also means that it follows the same semantic versioning rules as they were defined for [the Ably client library](#for-browsers). For example, to lock into a major or minor version of the Objects plugin, you can specify a specific version number such as https://cdn.ably.com/lib/objects.umd.min-2.js for all v2._ versions, or https://cdn.ably.com/lib/objects.umd.min-2.4.js for all v2.4._ versions, or you can lock into a single release with https://cdn.ably.com/lib/objects.umd.min-2.4.0.js. Note you can load the non-minified version by omitting `.min` from the URL such as https://cdn.ably.com/lib/objects.umd-2.js.
623
623
624
624
For more information about the LiveObjects product, see the [Ably LiveObjects documentation](https://ably.com/docs/products/liveobjects).
625
625
626
-
#### State Channel Modes
626
+
#### Objects Channel Modes
627
627
628
-
To use the LiveObjects feature, clients must attach to a channel with the correct channel mode:
628
+
To use the Objects on a channel, clients must attach to a channel with the correct channel mode:
629
629
630
-
- `state_subscribe` - required to retrieve state of Live Objects for a channel
631
-
- `state_publish` - required to create new and modify existing Live Objects on a channel
630
+
- `object_subscribe` - required to retrieve Objects for a channel
631
+
- `object_publish` - required to create new and modify existing Objects on a channel
The authentication token must include corresponding capabilities for the client to interact with LiveObjects.
644
+
The authentication token must include corresponding capabilities for the client to interact with Objects.
645
645
646
646
#### Getting the Root Object
647
647
648
-
The root object represents the top-level entry point for LiveObjects state within a channel. It gives access to all other nested Live Objects.
648
+
The root object represents the top-level entry point for Objects within a channel. It gives access to all other nested Live Objects.
649
649
650
650
```typescript
651
-
constroot=awaitliveObjects.getRoot();
651
+
constroot=awaitobjects.getRoot();
652
652
```
653
653
654
-
The root object is a `LiveMap` instance and serves as the starting point for storing and organizing LiveObjects state.
654
+
The root object is a `LiveMap` instance and serves as the starting point for storing and organizing Objects on a channel.
655
655
656
656
#### Live Object Types
657
657
658
658
LiveObjects currently supports two primary data structures; `LiveMap` and `LiveCounter`.
659
659
660
-
`LiveMap` - A key/value map data structure, similar to a JavaScript `Map`, where all changes are synchronized across clients in realtime. It allows you to store primitive values and other Live Objects, enabling a composable state.
660
+
`LiveMap` - A key/value map data structure, similar to a JavaScript `Map`, where all changes are synchronized across clients in realtime. It allows you to store primitive values and other Live Objects, enabling composability.
661
661
662
662
You can use `LiveMap` as follows:
663
663
664
664
```typescript
665
665
// root object is a LiveMap
666
-
constroot=awaitliveObjects.getRoot();
666
+
constroot=awaitobjects.getRoot();
667
667
668
668
// you can read values for a key with .get
669
669
root.get('foo');
@@ -690,7 +690,7 @@ await root.set('bar', 1);
690
690
awaitroot.set('baz', true);
691
691
awaitroot.set('qux', newUint8Array([21, 31]));
692
692
// as well as other live objects
693
-
constcounter=awaitliveObjects.createCounter();
693
+
constcounter=awaitobjects.createCounter();
694
694
awaitroot.set('quux', counter);
695
695
696
696
// and you can remove keys with .remove
@@ -702,7 +702,7 @@ await root.remove('name');
702
702
You can use `LiveCounter` as follows:
703
703
704
704
```typescript
705
-
constcounter=awaitliveObjects.createCounter();
705
+
constcounter=awaitobjects.createCounter();
706
706
707
707
// you can get current value of a counter with .value
708
708
counter.value();
@@ -714,14 +714,14 @@ await counter.decrement(2);
714
714
715
715
#### Subscribing to Updates
716
716
717
-
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.
717
+
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, subscribing ensures that your application reacts to external updates as soon as they are received.
718
718
719
719
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.
720
720
721
721
You can subscribe to updates on all Live Objects using subscription listeners as follows:
console.log('LiveCounter new value:', counter.value()); // can read the current value of the counter inside this callback
736
736
console.log('LiveCounter update details:', update); // and can get update details from the provided update object
@@ -775,18 +775,18 @@ root.unsubscribeAll();
775
775
New `LiveMap` and `LiveCounter` instances can be created as follows:
776
776
777
777
```typescript
778
-
constcounter=awaitliveObjects.createCounter(123); // with optional initial counter value
779
-
constmap=awaitliveObjects.createMap({ key:'value' }); // with optional initial map entries
778
+
constcounter=awaitobjects.createCounter(123); // with optional initial counter value
779
+
constmap=awaitobjects.createMap({ key:'value' }); // with optional initial map entries
780
780
```
781
781
782
-
To persist them within the LiveObjects state, they must be assigned to a parent `LiveMap` that is connected to the root object through the object hierarchy:
782
+
To persist them within the Objects state, they must be assigned to a parent `LiveMap` that is connected to the root object through the object hierarchy:
@@ -804,7 +804,7 @@ Batching allows multiple operations to be grouped into a single message that is
804
804
Within a batch callback, the `BatchContext` instance provides wrapper objects around regular Live Objects with a synchronous API for storing changes in the batch context.
Live Objects emit lifecycle events to signal critical state changes, such as synchronization progress and object deletions.
823
823
824
-
**Synchronization Events** - the `syncing` and `synced` events notify when the LiveObjects state is being synchronized with the Ably service. These events can be useful for displaying loading indicators, preventing user edits during synchronization, or triggering application logic when the data was loaded for the first time.
824
+
**Synchronization Events** - the `syncing` and `synced` events notify when the Objects state is being synchronized with the Ably service. These events can be useful for displaying loading indicators, preventing user edits during synchronization, or triggering application logic when the data was loaded for the first time.
825
825
826
826
```typescript
827
-
liveObjects.on('syncing', () => {
828
-
console.log('LiveObjects state is syncing...');
827
+
objects.on('syncing', () => {
828
+
console.log('Objects are syncing...');
829
829
// Example: Show a loading indicator
830
830
});
831
831
832
-
liveObjects.on('synced', () => {
833
-
console.log('LiveObjects state has been synced.');
832
+
objects.on('synced', () => {
833
+
console.log('Objects have been synced.');
834
834
// Example: Hide loading indicator
835
835
});
836
836
```
837
837
838
838
**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 accessible from the root map object) 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.
map.get('counter').value(); // autocompletion for counter method names
897
897
```
898
898
899
-
You can also provide typings for the LiveObjects state tree when calling the `liveObjects.getRoot` method, allowing you to have different state typings for different channels:
899
+
You can also provide typings for the channel Objects when calling the `objects.getRoot` method, allowing you to have different typings for different channels:
0 commit comments