ClientApi

ClientApi

Represents an API node at a remote server.

Constructor

new ClientApi(pProtocol, pRoute)

Parameters
Name Type Description
pProtocol object

The protocol object to be used for server communication.

pRoute Array.<any>

The stack of routes that led to this ClientApi pointer.

Members

connected :boolean

The connection state of the protocol this ClientApi uses.

proxified :Proxy

A proxy that returns this.route(A).proxified when property A is accessed and this.close(B) when called with parameter B. then and catch however are directly passed through.

Methods

catch(fail) → {Promise}

Shorthand for this.close().catch().

Parameters
Name Type Description
fail function

The fail function.

Returns

Rejects if this.close() rejects.

Type
Promise

close(dataopt) → {Promise}

Closes the Api via its protocol.

Parameters
Name Type Attributes Description
data any <optional>

The data to close with.

Returns

A promise that resolves to the return value of the remote API.

Type
Promise

observeConnection(observer) → {undefined}

Observe connection changes of the protocol this ClientApi uses.

Parameters
Name Type Description
observer function

The observer to use.

Returns
Type
undefined

route(…destination) → {ClientApi}

Routes the ClientApi via its protocol.

Parameters
Name Type Attributes Description
destination any <repeatable>

The destination to route to. Multiple destinations are handled like a chained ClientApi#route call.

Returns

A new ClientApi for the object the routing function returned.

Type
ClientApi

then(success, fail) → {Promise}

Shorthand for this.close().then().

Parameters
Name Type Description
success function

The success function.

fail function

The fail function.

Returns

Result of this.close().

Type
Promise

unobserveConnection(observer) → {undefined}

Removed connection observer from the protocol this ClientApi uses.

Parameters
Name Type Description
observer function

The observer to be removed.

Returns
Type
undefined