Service
Role#
- A service is a component that expose a generic API and generics business models to propose a kind of service (live, pvr, …).
- A service relies on one or more vendors API for its implementation.
- A service acts as a wrapper between the application and the vendors APIs.
- A service is a singleton and as all singletons it is lazy loaded
- A service is defined by an abstract class that must be implemented by vendors
Declaration#
Very simple !
import $Abstract from "@Abstract";
/**
* A simple test service
*
* @name TestService
* @class
* @service
* @extends Abstract
*/
export default $Abstract.declare("TestService", {
methods: /** @lends TestService.prototype */ {
myMethod: function() {
// Implement what ever you want
}
}
});
Expected Use#
The abstract service class must:
- Expose the public api,
- Define the abstract methods to be implemented by vendors,
- Manage cache (if needed),
- Define events and handles events propagation,
- Ensure that the abstract methods are called with valid argument(s) (ie check input args before calling abstracts),
- Handles the business models states changes,
- The API must be mostly asynchronous. If vendor API is synchronous, convert it to asynchronous with promises,
Conventions#
A synchronous method must be prefixed with the keyword Sync (ex: findSync()
)