Skip to content

RoliClient

Methods

addUpdateListener()

addUpdateListener<T>(data, listener): void

Adds an update listener to one or more Data so that when an update is received the listener is called. This does not subscribe the objects to updates.

Type parameters

T extends Data

Parameters

data: T | T[]

The objects to add the listener to.

listener: DataUpdateListener<T>

The listener function to add.

Returns

void

See

subscribeUpdates


clearUpdateListeners()

clearUpdateListeners(data): void

Removes all update listeners from one or more Data. This does not unsubscribe the objects from updates, it mearly removes all local update listener handlers.

Parameters

data: Data | Data[]

The objects to remove all update listeners.

Returns

void

See

  • unsubscribeUpdates
  • removeUpdateListener

closeConnections()

closeConnections(): void

Closes all open service connections and removes all Event and Data listeners. This doesn’t prevent new connections from being made nor new Event / data listeners from being setup and used.

Returns

void


getData()

getData<T>(dataType, primaryKey): Promise<null | T>

(async) Retrieves an existing instance of a Data-derived class from the service and returns it.

Type parameters

T extends Data

Parameters

dataType: DataConstructor<T>

The type of the object to get. E.g. The Player class that extends Data.

primaryKey: string

The primary key of the object to get.

Returns

Promise<null | T>

A promise that resolves to the object instance or null if the object wasn’t found.

Throws

When a failure occurs when talking to the service.


getEndpoint()

getEndpoint<T>(endpointType, primaryKey): T

Gets a callable proxy that can be used to make calls to an endpoint instance on the Roli backend. This doesn’t make a network call. Endpoints are created the first time a method is called on them.

Type parameters

T extends Endpoint

Parameters

endpointType: EndpointConstructor<T>

The type of the endpoint to get. E.g. The MyEndpoint class that extends Endpoint.

primaryKey: string

The primary key of the endpoint to get.

Returns

T

A callable, strongly typed Endpoint proxy.


removeEventListener()

removeEventListener<TS, TM>(source, eventType, listener): void

Removes a event listener so it is no longer handled by this client. Note: This does not unsubscribe this client from the event all together, this mearly removes the listener function handler. (note: A event subscription can have multiple listeners)

Type parameters

TS extends Endpoint | Data

TM extends Event

Parameters

source: TS

The source Data or Endpoint that was passed to the previous subscribeEvent call.

eventType: EventConstructor<TM>

The type of the event to remove the listener from.

listener: EventListener<TM>

The function instance you no longer wish to be called.

Returns

void


removeUpdateListener()

removeUpdateListener<T>(data, listener): void

Removes the update listener from one or more Data. This does not unsubscribe the objects from updates, it mearly removes the local update listener handler.

Type parameters

T extends Data

Parameters

data: T | T[]

The objects to remove the update listener from.

listener: DataUpdateListener<T>

The listener function to remove.

Returns

void


saveData()

saveData(…data): Promise<void>

(async) Pushes one or more Data-derived instances to the service and saves them to the datastore. Their changes are broadcasted to other clients listening for changes on those objects.

Parameters

• …data: Data[]

The objects to save.

Returns

Promise<void>

A promise that resolves when the object has been saved.

See

  • subscribeUpdates
  • addUpdateListener

Throws

When a failure occurs when talking to the service.


subscribeEvent()

subscribeEvent<TS, TM>(source, eventType, listener): Promise<void>

(async) Subscribes this client to a Event so that when a service endpoint sends it, this client receives it and calls the listener function.

Type parameters

TS extends Endpoint | Data

TM extends Event

Parameters

source: Endpoint | Data

The source Data or Endpoint to subscribe to.

eventType: EventConstructor<TM>

The type of the event to subscribe to. E.g. The PlayerAdded class that extends Event.

listener: EventListener<TM>

The function instance to be called to handle the event.

Returns

Promise<void>

A promise that resolves when the service has subscribed this client to the event.

See

unsubscribeEvent

Throws

When a failure occurs when talking to the service.


subscribeUpdates()

subscribeUpdates(data): Promise<void>

(async) Subscribes one or more Data instances to updates so that when other clients (or endpoints) make changes to them, the changes are sent to this client so the objects are kept up to date automatically.

Parameters

data: Data | Data[]

The objects to subscribe. E.g. An instance of the Player class that extends Data.

Returns

Promise<void>

A promise that resolves when the service has subscribed this client to object updates made to the objects in question.

See

addUpdateListener

Throws

When a failure occurs when talking to the service.


unsubscribeEvent()

unsubscribeEvent<TS, TM>(source, eventType): Promise<void>

(async) Unsubscribes this client from the Event so that it no longer handles it. This also removes all listeners.

Type parameters

TS extends Endpoint | Data

TM extends Event

Parameters

source: TS

The source Data or Endpoint that was passed to the previous subscribeEvent call.

eventType: EventConstructor<TM>

The type of the event to unsubscribe from. E.g. The PlayerAdded class that extends Event.

Returns

Promise<void>

A promise that resolves when the service has unsubscribed this client from the event.

See

subscribeEvent

Throws

When a failure occurs when talking to the service.


unsubscribeUpdates()

unsubscribeUpdates(data): Promise<void>

(async) Unsubscribes one or more Data instances from updates so they no longer receive changes made by other clients (or endpoints).

Parameters

data: Data | Data[]

The objects to unsubscribe. E.g. An instance of the Player class that extends Data.

Returns

Promise<void>

A promise that resolves when the service has unsubscribed this client from object updates made to the objects in question.

See

subscribeUpdates

Throws

When a failure occurs when talking to the service.


Generated using typedoc-plugin-markdown and TypeDoc