Service Interface
Both the Client Extensions API services and your application services use the same interface. The service interface consists of the following methods:
implement()
Create a method on a service and specify the implementation.
Parameter
Type
Description
methodName
String
The name of the method to create on your service
implementation
Function
The implementation of the method
Alternately, create several methods on a service at once by specifying an object consisting of multiple functions:
Parameters
Type
Description
implementations
Object
An object containing one or more functions to create on this service, where the keys are the names of the functions and the values are the implementations
invoke()
Call a method on a service. Any extra parameters passed to this method will be sent as arguments to the service method:
Parameters
Type
Description
methodName
String
The name of the method to call on the service
fire()
Fire an event from a service. Any extra parameters passed to this method will be passed to the callbacks defined by services that listen to this event:
Parameters
Type
Description
eventName
String
The name of the event to fire
listen()
Subscribe a service to an event that is fired by another service (or itself). This method returns a handle that can later be used to remove the listener:
Parameters
Type
Description
eventName
String
The name of the event to listen for
callback
Function
The function that will be called when the event is fired
The listen
namespace is the same as the namespace for methods, thus names must be unique across both service methods and events.
remove()
Unsubscribe a service from an event:
Parameters
Type
Description
eventName
String
The name of the event to unsubscribe from
handle
String
The handle returned by the call to listen
Last updated