Skip to content

Commit 61535dd

Browse files
committed
Consolidate docstring comments for Locations
1 parent 092fca7 commit 61535dd

File tree

1 file changed

+64
-194
lines changed

1 file changed

+64
-194
lines changed

src/Locations.ts

Lines changed: 64 additions & 194 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,57 @@ import SpaceUpdate from './SpaceUpdate.js';
1212
export namespace LocationsEvents {
1313
/**
1414
* The data attached to an {@link LocationsEventMap.update | `update`} event.
15+
*
16+
* The following is an example payload of a location event:
17+
*
18+
* ```json
19+
* {
20+
* "member": {
21+
* "clientId": "clemons#142",
22+
* "connectionId": "hd9743gjDc",
23+
* "isConnected": true,
24+
* "profileData": {
25+
* "username": "Claire Lemons",
26+
* "avatar": "https://slides-internal.com/users/clemons.png"
27+
* },
28+
* "location": {
29+
* "slide": "3",
30+
* "component": "slide-title"
31+
* },
32+
* "lastEvent": {
33+
* "name": "update",
34+
* "timestamp": 1972395669758
35+
* }
36+
* },
37+
* "previousLocation": {
38+
* "slide": "2",
39+
* "component": null
40+
* },
41+
* "currentLocation": {
42+
* "slide": "3",
43+
* "component": "slide-title"
44+
* }
45+
* }
46+
* ```
1547
*/
1648
export interface UpdateEvent {
1749
/**
1850
* The member whose location changed.
1951
*/
2052
member: SpaceMember;
2153
/**
22-
* <!-- MOVED FROM Locations.subscribe -->
2354
* The new location of the member.
2455
*/
2556
currentLocation: unknown;
2657
/**
27-
* <!-- MOVED FROM Locations.subscribe -->
2858
* The previous location of the member.
2959
*/
3060
previousLocation: unknown;
3161
}
3262
}
3363

3464
/**
35-
* The property names of `LocationsEventMap` are the names of the events emitted by { @link Locations }.
65+
* The property names of `LocationsEventMap` are the names of the events emitted by {@link Locations}.
3666
*/
3767
export interface LocationsEventMap {
3868
/**
@@ -42,25 +72,10 @@ export interface LocationsEventMap {
4272
}
4373

4474
/**
45-
* <!-- BEGIN WEBSITE DOCUMENTATION (https://github.com/ably/docs/blob/cb5de6a6a40abdcb0d9d5af825928dd62dc1ca64/content/spaces/locations.textile?plain=1#L9-L11) -->
46-
* The member location feature enables you to track where members are within a space, to see which part of your application they’re interacting with. A location could be the form field they have selected, the cell they’re currently editing in a spreadsheet, or the slide they’re viewing within a slide deck. Multiple members can be present in the same location.
47-
*
48-
* Member locations are used to visually display which component other members currently have selected, or are currently active on. Events are emitted whenever a member sets their location, such as when they click on a new cell, or slide. Events are received by members subscribed to location events and the UI component can be highlighted with the active member’s profile data to visually display their location.
75+
* [Member locations](https://ably.com/docs/spaces/locations) enable you to track where members are within a {@link Space | space}, to see which part of your application they’re interacting with. A location could be the form field they have selected, the cell they’re currently editing in a spreadsheet, or the slide they’re viewing within a slide deck. Multiple members can be present in the same location.
4976
*
50-
* <!-- END WEBSITE DOCUMENTATION -->
77+
* Location events are emitted whenever a member changes their location, such as by clicking on a new cell or slide. This enables UI components to be highlighted with the active member's profile data to visually display their location.
5178
*
52-
* <!-- BEGIN WEBSITE DOCUMENTATION (https://github.com/ably/docs/blob/cb5de6a6a40abdcb0d9d5af825928dd62dc1ca64/content/spaces/locations.textile?plain=1#L211-L215) -->
53-
* ## Member location foundations
54-
*
55-
* The Spaces SDK is built upon existing Ably functionality available in Ably’s Core SDKs. Understanding which core features are used to provide the abstractions in the Spaces SDK enables you to manage space state and build additional functionality into your application.
56-
*
57-
* Member locations build upon the functionality of the Pub/Sub Channels [presence](https://ably.com/docs/presence-occupancy/presence) feature. Members are entered into the presence set when they {@link Space.enter | enter the space}.
58-
*
59-
* <!-- END WEBSITE DOCUMENTATION -->
60-
*
61-
* <!-- BEGIN CLASS-DEFINITIONS DOCUMENTATION -->
62-
* Handles the tracking of member locations within a space. Inherits from {@link EventEmitter}.
63-
* <!-- END CLASS-DEFINITIONS DOCUMENTATION -->
6479
*/
6580
export default class Locations extends EventEmitter<LocationsEventMap> {
6681
private lastLocationUpdate: Record<string, PresenceMember['data']['locationUpdate']['id']> = {};
@@ -103,26 +118,19 @@ export default class Locations extends EventEmitter<LocationsEventMap> {
103118
}
104119

105120
/**
106-
* <!-- BEGIN WEBSITE DOCUMENTATION (https://github.com/ably/docs/blob/cb5de6a6a40abdcb0d9d5af825928dd62dc1ca64/content/spaces/locations.textile?plain=1#L15-L25) -->
107-
* Use the `set()` method to emit a location event in realtime when a member changes their location. This will be received by all location subscribers to inform them of the location change. A `location` can be any JSON-serializable object, such as a slide number or element ID.
121+
* Set the location of a member an emit an {@link LocationsEvents.UpdateEvent | `update`} event.
108122
*
109-
* A member must have been { @link Space.enter | entered } into the space to set their location.
123+
* A `location` can be any JSON-serializable object, such as a slide number or element ID.
110124
*
111-
* The `set()` method is commonly combined with [`addEventListener()`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener) or a React [synthetic event](https://react.dev/learn/responding-to-events#adding-event-handlers), such as `onClick` or `onHover`.
125+
* A member must have been {@link Space.enter | entered} into the space to set their location.
112126
*
113127
* The following is an example of a member setting their location to a specific slide number, and element on that slide:
114128
*
115129
* ```javascript
116130
* await space.locations.set({ slide: '3', component: 'slide-title' });
117131
* ```
118-
* <!-- END WEBSITE DOCUMENTATION -->
119132
*
120-
* <!-- BEGIN CLASS-DEFINITIONS DOCUMENTATION -->
121-
* Set your current location. The `location` argument can be any JSON-serializable object. Emits a `locationUpdate` event to all connected clients in this space.
122-
* <!-- END CLASS-DEFINITIONS DOCUMENTATION -->
123-
*
124-
* <!-- Second sentence copied from above -->
125-
* @param location The new location. Can be any JSON-serializable object, such as a slide number or element ID.
133+
* @param location The member's new location. Can be any JSON-serializable object.
126134
*/
127135
async set(location: unknown) {
128136
const self = await this.space.members.getSelf();
@@ -138,14 +146,13 @@ export default class Locations extends EventEmitter<LocationsEventMap> {
138146
/**
139147
* {@label WITH_EVENTS}
140148
*
141-
* <!-- BEGIN WEBSITE DOCUMENTATION (https://github.com/ably/docs/blob/cb5de6a6a40abdcb0d9d5af825928dd62dc1ca64/content/spaces/locations.textile?plain=1#L29-L91) -->
142-
* Subscribe to location events by registering a listener. Location events are emitted whenever a member changes location by calling {@link set}.
149+
* Subscribe to location events by registering a listener. Location events are emitted whenever a member {@link Locations.set | changes} their location.
143150
*
144-
* All location changes are {@link LocationsEventMap.update | `update`} events. When a location update is received, clear the highlight from the UI component of the member’s {@link LocationsEvents.UpdateEvent.previousLocation | `previousLocation`} and add it to {@link LocationsEvents.UpdateEvent.currentLocation | `currentLocation`}.
151+
* All location changes are `update` events. When a location update is received, clear the highlight from the UI component of the member’s {@link LocationsEvents.UpdateEvent.previousLocation | `previousLocation`} and add it to {@link LocationsEvents.UpdateEvent.currentLocation | `currentLocation`}.
145152
*
146153
* > **Note**
147154
* >
148-
* > A location update is also emitted when a member {@link Space.leave | leaves} a space. The member’s {@link LocationsEvents.UpdateEvent.currentLocation | `currentLocation` } will be `null` for these events so that any UI component highlighting can be cleared.
155+
* > A location update is also emitted when a member is {@link MembersEventMap.remove | removed} from a space. The member’s {@link LocationsEvents.UpdateEvent.currentLocation | `currentLocation` } will be `null` for these events so that any UI component highlighting can be cleared. Member location subscription listeners only trigger on events related to members’ locations. Each event only contains the payload of the member that triggered it. Alternatively, {@link Space.subscribe | space state } can be subscribed to which returns an array of all members with their latest state every time any event is triggered.
149156
*
150157
* The following is an example of subscribing to location events:
151158
*
@@ -154,65 +161,9 @@ export default class Locations extends EventEmitter<LocationsEventMap> {
154161
* console.log(locationUpdate);
155162
* });
156163
* ```
157-
* The following is an example payload of a location event. Information about location is returned in {@link LocationsEvents.UpdateEvent.currentLocation | `currentLocation`} and {@link LocationsEvents.UpdateEvent.previousLocation | `previousLocation`}:
158164
*
159-
* ```json
160-
* {
161-
* "member": {
162-
* "clientId": "clemons#142",
163-
* "connectionId": "hd9743gjDc",
164-
* "isConnected": true,
165-
* "profileData": {
166-
* "username": "Claire Lemons",
167-
* "avatar": "https://slides-internal.com/users/clemons.png"
168-
* },
169-
* "location": {
170-
* "slide": "3",
171-
* "component": "slide-title"
172-
* },
173-
* "lastEvent": {
174-
* "name": "update",
175-
* "timestamp": 1972395669758
176-
* }
177-
* },
178-
* "previousLocation": {
179-
* "slide": "2",
180-
* "component": null
181-
* },
182-
* "currentLocation": {
183-
* "slide": "3",
184-
* "component": "slide-title"
185-
* }
186-
* }
187-
* ```
188-
* The following are the properties of a location event payload:
189-
*
190-
* > **Moved documentation**
191-
* >
192-
* > This documentation has been moved to { @link LocationsEvents.UpdateEvent }.
193-
*
194-
* > **Further reading**
195-
* >
196-
* > Member location subscription listeners only trigger on events related to members’ locations. Each event only contains the payload of the member that triggered it. Alternatively, {@link Space.subscribe | space state } can be subscribed to which returns an array of all members with their latest state every time any event is triggered.
197-
*
198-
* <!-- END WEBSITE DOCUMENTATION -->
199-
*
200-
* <!-- BEGIN CLASS-DEFINITIONS DOCUMENTATION -->
201-
* Listen to events for locations. See {@link EventEmitter} for overloaded usage.
202-
*
203-
* Available events:
204-
*
205-
* - ##### **update**
206-
*
207-
* Fires when a member updates their location. The argument supplied to the event listener is an UpdateEvent.
208-
*
209-
* ```ts
210-
* space.locations.subscribe('update', (locationUpdate: LocationsEvents.UpdateEvent) => {});
211-
* ```
212-
* <!-- END CLASS-DEFINITIONS DOCUMENTATION -->
213-
*
214-
* @param eventOrEvents The event name or an array of event names.
215-
* @param listener The listener to add.
165+
* @param eventOrEvents An event name, or an array of event names.
166+
* @param listener An event listener.
216167
*
217168
* @typeParam K A type which allows one or more names of the properties of the {@link LocationsEventMap} type.
218169
*/
@@ -221,9 +172,9 @@ export default class Locations extends EventEmitter<LocationsEventMap> {
221172
listener?: EventListener<LocationsEventMap, K>,
222173
): void;
223174
/**
224-
* Behaves the same as { @link subscribe:WITH_EVENTS | the overload which accepts one or more event names }, but subscribes to _all_ events.
175+
* Subscribe to location updates by registering a listener for all events.
225176
*
226-
* @param listener The listener to add.
177+
* @param listener An event listener.
227178
*/
228179
subscribe(listener?: EventListener<LocationsEventMap, keyof LocationsEventMap>): void;
229180
subscribe<K extends keyof LocationsEventMap>(
@@ -246,31 +197,16 @@ export default class Locations extends EventEmitter<LocationsEventMap> {
246197
/**
247198
* {@label WITH_EVENTS}
248199
*
249-
* <!-- BEGIN WEBSITE DOCUMENTATION (https://github.com/ably/docs/blob/cb5de6a6a40abdcb0d9d5af825928dd62dc1ca64/content/spaces/locations.textile?plain=1#L95-L107) -->
250200
* Unsubscribe from location events to remove previously registered listeners.
251201
*
252202
* The following is an example of removing a listener for location update events:
253203
*
254204
* ```javascript
255205
* space.locations.unsubscribe('update', listener);
256206
* ```
257-
* Or remove all listeners:
258207
*
259-
* ```javascript
260-
* space.locations.unsubscribe();
261-
* ```
262-
* <!-- END WEBSITE DOCUMENTATION -->
263-
*
264-
* <!-- BEGIN CLASS-DEFINITIONS DOCUMENTATION -->
265-
* Remove all event listeners, all event listeners for an event, or specific listeners. See {@link EventEmitter} for detailed usage.
266-
*
267-
* ```ts
268-
* space.locations.unsubscribe('update');
269-
* ```
270-
* <!-- END CLASS-DEFINITIONS DOCUMENTATION -->
271-
*
272-
* @param eventOrEvents The event name or an array of event names.
273-
* @param listener The listener to remove.
208+
* @param eventOrEvents An event name, or an array of event names.
209+
* @param listener An event listener.
274210
*
275211
* @typeParam K A type which allows one or more names of the properties of the {@link LocationsEventMap} type.
276212
*/
@@ -279,9 +215,15 @@ export default class Locations extends EventEmitter<LocationsEventMap> {
279215
listener?: EventListener<LocationsEventMap, K>,
280216
): void;
281217
/**
282-
* Behaves the same as { @link unsubscribe:WITH_EVENTS | the overload which accepts one or more event names }, but unsubscribes from _all_ events.
218+
* Unsubscribe from all events to remove previously registered listeners.
219+
*
220+
* The following is an example of removing a listener for all events:
221+
*
222+
* ```javascript
223+
* space.locations.unsubscribe(listener);
224+
* ```
283225
*
284-
* @param listener The listener to remove.
226+
* @param listener An event listener.
285227
*/
286228
unsubscribe(listener?: EventListener<LocationsEventMap, keyof LocationsEventMap>): void;
287229
unsubscribe<K extends keyof LocationsEventMap>(
@@ -302,37 +244,27 @@ export default class Locations extends EventEmitter<LocationsEventMap> {
302244
}
303245

304246
/**
305-
* <!-- This is to avoid duplication of the website documentation. -->
306-
* See the documentation for {@link getAll}.
247+
* Retrieve the location of the current member in a one-off call.
307248
*
308-
* <!-- BEGIN CLASS-DEFINITIONS DOCUMENTATION -->
309-
* Get location for self.
249+
* The following is an example of retrieving a member's own location:
310250
*
311-
* Example:
312-
*
313-
* ```ts
251+
* ```javascript
314252
* const myLocation = await space.locations.getSelf();
315253
* ```
316-
* <!-- END CLASS-DEFINITIONS DOCUMENTATION -->
317254
*/
318255
async getSelf(): Promise<unknown> {
319256
const self = await this.space.members.getSelf();
320257
return self ? self.location : null;
321258
}
322259

323260
/**
324-
* <!-- This is to avoid duplication of the website documentation. -->
325-
* See the documentation for {@link getAll}.
261+
* Retrieve the locations of all members other than the member themselves in a one-off call.
326262
*
327-
* <!-- BEGIN CLASS-DEFINITIONS DOCUMENTATION -->
328-
* Get location for other members
263+
* The following is an example of retrieving the locations of all members, except the member themselves:
329264
*
330-
* Example:
331-
*
332-
* ```ts
265+
* ```javascript
333266
* const otherLocations = await space.locations.getOthers()
334267
* ```
335-
* <!-- END CLASS-DEFINITIONS DOCUMENTATION -->
336268
*/
337269
async getOthers(): Promise<Record<string, unknown>> {
338270
const members = await this.space.members.getOthers();
@@ -344,75 +276,13 @@ export default class Locations extends EventEmitter<LocationsEventMap> {
344276
}
345277

346278
/**
347-
* <!-- BEGIN WEBSITE DOCUMENTATION (https://github.com/ably/docs/blob/cb5de6a6a40abdcb0d9d5af825928dd62dc1ca64/content/spaces/locations.textile?plain=1#L111-L172) -->
348-
* Member locations can also be retrieved in one-off calls. These are local calls and retrieve the location of members retained in memory by the SDK.
349-
*
350-
* The following is an example of retrieving a member’s own location:
351-
*
352-
* ```javascript
353-
* const myLocation = await space.locations.getSelf();
354-
* ```
355-
* The following is an example payload returned by `space.locations.getSelf()`. It will return the properties of the member’s `location`:
356-
*
357-
* ```json
358-
* {
359-
* "slide": "3",
360-
* "component": "slide-title"
361-
* }
362-
* ```
363-
* The following is an example of retrieving the location objects of all members other than the member themselves.
364-
*
365-
* ```javascript
366-
* const othersLocations = await space.locations.getOthers();
367-
* ```
368-
* The following is an example payload returned by `space.locations.getOthers()`: It will return the properties of all member’s `location` by their `connectionId`:
279+
* Retrieve the location of all members in a one-off call.
369280
*
370-
* ```json
371-
* {
372-
* "xG6H3lnrCn": {
373-
* "slide": "1",
374-
* "component": "textBox-1"
375-
* },
376-
* "el29SVLktW": {
377-
* "slide": "1",
378-
* "component": "image-2"
379-
* }
380-
* }
381-
* ```
382-
* The following is an example of retrieving the location objects of all members, including the member themselves:
281+
* The following is an example of retrieving the locations of all members:
383282
*
384283
* ```javascript
385284
* const allLocations = await space.locations.getAll();
386285
* ```
387-
* The following is an example payload returned by `space.locations.getAll()`. It will return the properties of all member’s `location` by their `connectionId`:
388-
*
389-
* ```json
390-
* {
391-
* "xG6H3lnrCn": {
392-
* "slide": "1",
393-
* "component": "textBox-1"
394-
* },
395-
* "el29SVLktW": {
396-
* "slide": "1",
397-
* "component": "image-2"
398-
* },
399-
* "dieF3291kT": {
400-
* "slide": "3",
401-
* "component": "slide-title"
402-
* }
403-
* }
404-
* ```
405-
* <!-- END WEBSITE DOCUMENTATION -->
406-
*
407-
* <!-- BEGIN CLASS-DEFINITIONS DOCUMENTATION -->
408-
* Get location for all members.
409-
*
410-
* Example:
411-
*
412-
* ```ts
413-
* const allLocations = await space.locations.getAll();
414-
* ```
415-
* <!-- END CLASS-DEFINITIONS DOCUMENTATION -->
416286
*/
417287
async getAll(): Promise<Record<string, unknown>> {
418288
const members = await this.space.members.getAll();

0 commit comments

Comments
 (0)