Skip to content

Commit

Permalink
Update class definitions
Browse files Browse the repository at this point in the history
I've tried to organise this to include the members namespace, and tried
to keep the examples consistent.
  • Loading branch information
surminus committed Aug 16, 2023
1 parent 8c81a79 commit 27384dc
Showing 1 changed file with 28 additions and 17 deletions.
45 changes: 28 additions & 17 deletions docs/class-definitions.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,24 @@ await space.updateProfileData((oldProfileData) => {
})
```

# Members

Handles members within a space.

## Methods

### subscribe

Listen to events for the space. See [EventEmitter](/docs/usage.md#event-emitters) for overloading usage.

Available events:

- #### **membersUpdate**
- #### **update**

Listen to updates to members.

```ts
space.subscribe('membersUpdate', (members: SpaceMember[]) => {});
space.members.subscribe('update', (members: SpaceMember[]) => {});
```

Triggers on:
Expand All @@ -178,42 +184,42 @@ Available events:
Listen to enter events of members.

```ts
space.subscribe('enter', (member: SpaceMember) => {})
space.members.subscribe('enter', (member: SpaceMember) => {})
```
The argument supplied to the callback is a [SpaceMember](#spacemember) object representing the member entering the space.

- #### **leave**

Listen to leave events of members. Note that the leave event will only fire once the [offlineTimeout](#spaceoptions) has passed.

```ts
space.subscribe('leave', (member: SpaceMember) => {})
space.members.subscribe('leave', (member: SpaceMember) => {})
```

The argument supplied to the callback is a [SpaceMember](#spacemember) object representing the member leaving the space.

### off
### unsubscribe

Remove all event listeners, all event listeners for an event, or specific listeners. See [EventEmitter](/docs/usage.md#event-emitters) for detailed usage.

```ts
space.off('enter');
space.members.unsubscribe('enter');
```

### getMembers
### getAll

Returns an array of all [SpaceMember](#spacemember) objects (members) currently in the space, including any who have left and not yet timed out. (_see: [offlineTimeout](#spaceoptions)_)

```ts
type getMembers = () => SpaceMember[];
space.members.getAll();
```

### getSelf

Gets the [SpaceMember](#spacemember) object which relates to the local connection. Will return `undefined` if the client hasn't entered the space yet.

```ts
type getSelf = () => SpaceMember | undefined;
space.members.getSelf();
```

## Related Types
Expand Down Expand Up @@ -280,17 +286,22 @@ Set your current location. [Location](#location-1) can be any JSON-serializable
type set = (update: Location) => void;
```
### getSelf

Get location for self
```ts
space.locations.getSelf()
space.locations.getSelf();
```

### getAll

Get location for all members

```ts
space.locations.getAll()
space.locations.getAll();
```

### getOthers

Get location for other members

```ts
Expand All @@ -313,12 +324,12 @@ Available events:
space.locations.subscribe('locationUpdate', (locationUpdate: LocationUpdate) => {});
```

### off
### unsubscribe

Remove all event listeners, all event listeners for an event, or specific listeners. See [EventEmitter](/docs/usage.md#event-emitters) for detailed usage.

```ts
space.locations.off('locationUpdate');
space.locations.unsubscribe('locationUpdate');
```

## Related types
Expand Down Expand Up @@ -423,12 +434,12 @@ Available events:
space.cursors.subscribe('cursorsUpdate', (cursorUpdate: CursorUpdate) => {});
```
### off
### unsubscribe
Remove all event listeners, all event listeners for an event, or specific listeners. See [EventEmitter](/docs/usage.md#event-emitters) for detailed usage.
```ts
space.cursors.off('cursorsUpdate');
space.cursors.unsubscribe('update');
```
## Related types
Expand Down Expand Up @@ -464,4 +475,4 @@ Represent data that can be associated with a cursor update.
```ts
type CursorData = Record<string, unknown>;
```
```

0 comments on commit 27384dc

Please sign in to comment.