Skip to content

Commit 9d98638

Browse files
authored
Merge pull request #1982 from ably/PUB-1242/rename-to-objects
[PUB-1242] Rename "LiveObjects" to "Objects" when referencing a channel feature
2 parents b7e3887 + 706d4ba commit 9d98638

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1006
-1068
lines changed

Gruntfile.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ module.exports = function (grunt) {
7373
});
7474
});
7575

76-
grunt.registerTask('build', ['webpack:all', 'build:browser', 'build:node', 'build:push', 'build:liveobjects']);
76+
grunt.registerTask('build', ['webpack:all', 'build:browser', 'build:node', 'build:push', 'build:objects']);
7777

7878
grunt.registerTask('all', ['build', 'requirejs']);
7979

@@ -138,13 +138,13 @@ module.exports = function (grunt) {
138138
});
139139
});
140140

141-
grunt.registerTask('build:liveobjects', function () {
141+
grunt.registerTask('build:objects', function () {
142142
var done = this.async();
143143

144144
Promise.all([
145-
esbuild.build(esbuildConfig.liveObjectsPluginConfig),
146-
esbuild.build(esbuildConfig.liveObjectsPluginCdnConfig),
147-
esbuild.build(esbuildConfig.minifiedLiveObjectsPluginCdnConfig),
145+
esbuild.build(esbuildConfig.objectsPluginConfig),
146+
esbuild.build(esbuildConfig.objectsPluginCdnConfig),
147+
esbuild.build(esbuildConfig.minifiedObjectsPluginCdnConfig),
148148
])
149149
.then(() => {
150150
done(true);
@@ -157,7 +157,7 @@ module.exports = function (grunt) {
157157
grunt.registerTask('test:webserver', 'Launch the Mocha test web server on http://localhost:3000/', [
158158
'build:browser',
159159
'build:push',
160-
'build:liveobjects',
160+
'build:objects',
161161
'checkGitSubmodules',
162162
'mocha:webserver',
163163
]);

README.md

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -588,82 +588,82 @@ For more information on publishing push notifications over Ably, see the [Ably p
588588
589589
### LiveObjects
590590
591-
#### Using the plugin
591+
#### Using the Objects plugin
592592
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.
594594
595595
```typescript
596596
import * as Ably from 'ably';
597-
import LiveObjects from 'ably/liveobjects';
597+
import Objects from 'ably/objects';
598598

599599
const client = new Ably.Realtime({
600600
...options,
601-
plugins: { LiveObjects },
601+
plugins: { Objects },
602602
});
603603
```
604604
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.
606606
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):
608608
609609
```html
610-
<script src="https://cdn.ably.com/lib/liveobjects.umd.min-2.js"></script>
610+
<script src="https://cdn.ably.com/lib/objects.umd.min-2.js"></script>
611611
```
612612
613-
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:
614614
615615
```typescript
616616
const client = new Ably.Realtime({
617617
...options,
618-
plugins: { LiveObjects: AblyLiveObjectsPlugin },
618+
plugins: { Objects: AblyObjectsPlugin },
619619
});
620620
```
621621
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.
623623
624624
For more information about the LiveObjects product, see the [Ably LiveObjects documentation](https://ably.com/docs/products/liveobjects).
625625
626-
#### State Channel Modes
626+
#### Objects Channel Modes
627627
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:
629629
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
632632
633633
```typescript
634634
const client = new Ably.Realtime({
635635
// authentication options
636636
...options,
637-
plugins: { LiveObjects },
637+
plugins: { Objects },
638638
});
639-
const channelOptions = { modes: ['state_subscribe', 'state_publish'] };
640-
const channel = client.channels.get('my_live_objects_channel', channelOptions);
641-
const liveObjects = channel.liveObjects;
639+
const channelOptions = { modes: ['object_subscribe', 'object_publish'] };
640+
const channel = client.channels.get('my_objects_channel', channelOptions);
641+
const objects = channel.objects;
642642
```
643643
644-
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.
645645
646646
#### Getting the Root Object
647647
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.
649649
650650
```typescript
651-
const root = await liveObjects.getRoot();
651+
const root = await objects.getRoot();
652652
```
653653
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.
655655
656656
#### Live Object Types
657657
658658
LiveObjects currently supports two primary data structures; `LiveMap` and `LiveCounter`.
659659
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.
661661
662662
You can use `LiveMap` as follows:
663663
664664
```typescript
665665
// root object is a LiveMap
666-
const root = await liveObjects.getRoot();
666+
const root = await objects.getRoot();
667667

668668
// you can read values for a key with .get
669669
root.get('foo');
@@ -690,7 +690,7 @@ await root.set('bar', 1);
690690
await root.set('baz', true);
691691
await root.set('qux', new Uint8Array([21, 31]));
692692
// as well as other live objects
693-
const counter = await liveObjects.createCounter();
693+
const counter = await objects.createCounter();
694694
await root.set('quux', counter);
695695

696696
// and you can remove keys with .remove
@@ -702,7 +702,7 @@ await root.remove('name');
702702
You can use `LiveCounter` as follows:
703703
704704
```typescript
705-
const counter = await liveObjects.createCounter();
705+
const counter = await objects.createCounter();
706706

707707
// you can get current value of a counter with .value
708708
counter.value();
@@ -714,14 +714,14 @@ await counter.decrement(2);
714714
715715
#### Subscribing to Updates
716716
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.
718718
719719
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.
720720
721721
You can subscribe to updates on all Live Objects using subscription listeners as follows:
722722
723723
```typescript
724-
const root = await liveObjects.getRoot();
724+
const root = await objects.getRoot();
725725

726726
// subscribe to updates on a LiveMap
727727
root.subscribe((update: LiveMapUpdate) => {
@@ -730,7 +730,7 @@ root.subscribe((update: LiveMapUpdate) => {
730730
});
731731

732732
// subscribe to updates on a LiveCounter
733-
const counter = await liveObjects.createCounter();
733+
const counter = await objects.createCounter();
734734
counter.subscribe((update: LiveCounterUpdate) => {
735735
console.log('LiveCounter new value:', counter.value()); // can read the current value of the counter inside this callback
736736
console.log('LiveCounter update details:', update); // and can get update details from the provided update object
@@ -775,18 +775,18 @@ root.unsubscribeAll();
775775
New `LiveMap` and `LiveCounter` instances can be created as follows:
776776
777777
```typescript
778-
const counter = await liveObjects.createCounter(123); // with optional initial counter value
779-
const map = await liveObjects.createMap({ key: 'value' }); // with optional initial map entries
778+
const counter = await objects.createCounter(123); // with optional initial counter value
779+
const map = await objects.createMap({ key: 'value' }); // with optional initial map entries
780780
```
781781
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:
783783
784784
```typescript
785-
const root = await liveObjects.getRoot();
785+
const root = await objects.getRoot();
786786

787-
const counter = await liveObjects.createCounter();
788-
const map = await liveObjects.createMap({ counter });
789-
const outerMap = await liveObjects.createMap({ map });
787+
const counter = await objects.createCounter();
788+
const map = await objects.createMap({ counter });
789+
const outerMap = await objects.createMap({ map });
790790

791791
await root.set('outerMap', outerMap);
792792

@@ -804,7 +804,7 @@ Batching allows multiple operations to be grouped into a single message that is
804804
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.
805805
806806
```typescript
807-
await liveObjects.batch((ctx) => {
807+
await objects.batch((ctx) => {
808808
const root = ctx.getRoot();
809809

810810
root.set('foo', 'bar');
@@ -821,24 +821,24 @@ await liveObjects.batch((ctx) => {
821821
822822
Live Objects emit lifecycle events to signal critical state changes, such as synchronization progress and object deletions.
823823
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.
825825
826826
```typescript
827-
liveObjects.on('syncing', () => {
828-
console.log('LiveObjects state is syncing...');
827+
objects.on('syncing', () => {
828+
console.log('Objects are syncing...');
829829
// Example: Show a loading indicator
830830
});
831831

832-
liveObjects.on('synced', () => {
833-
console.log('LiveObjects state has been synced.');
832+
objects.on('synced', () => {
833+
console.log('Objects have been synced.');
834834
// Example: Hide loading indicator
835835
});
836836
```
837837
838838
**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.
839839
840840
```typescript
841-
const root = await liveObjects.getRoot();
841+
const root = await objects.getRoot();
842842
const counter = root.get('counter');
843843

844844
counter.on('deleted', () => {
@@ -850,23 +850,23 @@ counter.on('deleted', () => {
850850
To unsubscribe from lifecycle events:
851851
852852
```typescript
853-
// same API for channel.liveObjects and LiveObject instances
853+
// same API for channel.objects and LiveObject instances
854854
// use dedicated off function from the .on call
855-
const { off } = liveObjects.on('synced', () => {});
855+
const { off } = objects.on('synced', () => {});
856856
off();
857857

858858
// call .off with an event name and a listener reference
859859
const listener = () => {};
860-
liveObjects.on('synced', listener);
861-
liveObjects.off('synced', listener);
860+
objects.on('synced', listener);
861+
objects.off('synced', listener);
862862

863863
// deregister all listeners using .offAll
864-
liveObjects.offAll();
864+
objects.offAll();
865865
```
866866
867-
#### Typing LiveObjects
867+
#### Typing Objects
868868
869-
You can provide your own TypeScript typings for LiveObjects by providing a globally defined `LiveObjectsTypes` interface.
869+
You can provide your own TypeScript typings for Objects by providing a globally defined `ObjectsTypes` interface.
870870
871871
```typescript
872872
// file: ably.config.d.ts
@@ -880,23 +880,23 @@ type MyCustomRoot = {
880880
};
881881

882882
declare global {
883-
export interface LiveObjectsTypes {
883+
export interface ObjectsTypes {
884884
root: MyCustomRoot;
885885
}
886886
}
887887
```
888888
889-
This will enable code completion and editor hints when interacting with the LiveObjects API:
889+
This will enable code completion and editor hints when interacting with the Objects API:
890890
891891
```typescript
892-
const root = await liveObjects.getRoot(); // uses types defined by global LiveObjectsTypes interface by default
892+
const root = await objects.getRoot(); // uses types defined by global ObjectsTypes interface by default
893893

894894
const map = root.get('map'); // LiveMap<{ foo: string; counter: LiveCounter }>
895895
map.set('foo', 1); // TypeError
896896
map.get('counter').value(); // autocompletion for counter method names
897897
```
898898
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:
900900
901901
```typescript
902902
type ReactionsRoot = {
@@ -908,8 +908,8 @@ type PollsRoot = {
908908
currentPoll: LiveMap;
909909
};
910910

911-
const reactionsRoot = await reactionsChannel.liveObjects.getRoot<ReactionsRoot>();
912-
const pollsRoot = await pollsChannel.liveObjects.getRoot<PollsRoot>();
911+
const reactionsRoot = await reactionsChannel.objects.getRoot<ReactionsRoot>();
912+
const pollsRoot = await pollsChannel.objects.getRoot<PollsRoot>();
913913
```
914914
915915
## Delta Plugin

0 commit comments

Comments
 (0)