Class: Communicator

Communicator

new Communicator(options)

Parameters:
Name Type Description
options Object Object containing the properties listed below
Properties:
Name Type Description
defaultAdapter String The default Adapter (name) for Connections
defaultConnection String The default Connection (name) for Requests
adapters Object.<Object> Adapters that should be registered on construct
connections Object.<Object> Connections that should be registered on construct
requests Object.<Object> Requests that should be registered on construct
To Do:
  • validate options
Example
import Communicator from 'frontend-communicator';

const communicator = Communicator({

  name: 'some-unique-name-for-the-communicator',
  defaultConnection: 'local-xhr',
  defaultAdapter: 'XHR',
  adapters: {...},
  connections: {...},
  requests: {...}

});

export default communicator;

Members

adapters :Object

Object that contains all registered Adapters on this Communicator
Type:
  • Object
Example
communicator.adapters.XHR;

connections :Object

Object that contains all registered Connections on this Communicator
Type:
  • Object
Example
communicator.connections['local-xhr'].post('/some/relative/path/to/connection/url', data)
  .then(...);

name :String

Name of the Communicator instance
Type:
  • String
Example
communicator.name; // name provided to factory

options :Object

Object containing the properties provided to the Communicator factory
Type:
  • Object
Example
communicator.options; // options provided to factory

requests :Object

Object that contains all registered Requests on this Communicator
Type:
  • Object
Example
communicator.requests['local-xhr'].user.login.execute('/some/relative/path/to/connection/url', data)
  .then(...);

servers :Object

Object that contains all registered Requests of all Connections on this Communicator
Type:
  • Object
Example
communicator.servers['local-xhr'].user.login()
  .then(...);

Methods

Adapter(options) → {Adapter}

Registers an Adapter on this Communicator
Parameters:
Name Type Description
options Object Object containing the properties for an Adapter
Returns:
Type
Adapter
Example
const adapter = communicator.Adapter({
  name: 'XHR',
  connect() {...},
  disconnect() {...},
  request() {...},
  ...
});

connect(connection) → {Promise}

Connects to a specified connection
Parameters:
Name Type Argument Default Description
connection String <optional>
this.defaultConnection The name of the Connection to connect to.
Returns:
A promise that resolves when the connection has been established
Type
Promise
Example
communicator.connect('local-xhr')
  .then(...);
// or, when having set a defaultConnection,
communicator.defaultConnection = 'local-xhr';
communicator.connect()
  .then(...);

Connection(options) → {Connection}

Registers an Connection on this Communicator
Parameters:
Name Type Description
options Object Object containing the properties for a Connection
Returns:
Type
Connection
Example
const connection = communicator.Connection({
  name: 'local-xhr',
  adapter: 'XHR',
  url: 'http://localhost:1337'
});

Request(options) → {Request}

Registers an Request on this Communicator
Parameters:
Name Type Description
options Object Object containing the properties for a Request
Returns:
Type
Request
Example
const request = communicator.Request({
  name: 'user.login',
  connection: 'local-xhr',
  route: '/user/login',
  method: 'get,
  ...
});
Rik Hoffbauer 2015
Documentation generated by JSDoc 3.4.0 on 2015-12-01T13:53:50+01:00