Service

class
 new Service()  extends EventEmitter

Option name Type Description

Use this object for representing a service in the application
A Service is a singleton in the application, that is init after all others services are created

You can use a Service to create Listeners or implement shared behavior between others services

class Service extends EventEmitter {

constructor

constructor
 Service.prototype.constructor() 

Option name Type Description
webda Webda
  • The main instance of Webda
name String
  • The name of the service
params Object
  • The parameters block define in the configuration file
constructor (webda, name, params) {
	super();
	this._webda = webda;
	this._name = name;
	this._params = params;
}

toPublicJSON

method
 Service.prototype.toPublicJSON() 

Option name Type Description
object Object
  • The object to export
return String

The export of the strip object ( removed all attribute with _ )

Convert an object to JSON using the Webda json filter

toPublicJSON(object) {
	return this._webda.toPublicJSON(object);
}

init

method
 Service.prototype.init() 

Option name Type Description
config

for the host so you can add your own route here

Will be called after all the Services are created

init(config) {}

install

method
 Service.prototype.install() 

Option name Type Description

For future use, while deploying this should be call so the service can create what it needs if necessary

install(params) {}

uninstall

method
 Service.prototype.uninstall() 

Option name Type Description

For future use, while undeploying this should be call so the service can create what it needs if necessary

uninstall(params) {}

emit

method
 Service.prototype.emit() 

Emit the event with data and wait for Promise to finish if listener returned a Promise

emit(event, data) {
	var result;
	var promises = [];
	var listeners = this.listeners(event);
	for (var i in listeners) {
		result = listeners[i](data);
		if (result instanceof Promise) {
			promises.push(result);
		}
	}
	return Promise.all(promises);
}

getModda

method
 Service.getModda() 

Return the Modda definition if any

static getModda() {}

__clean

method
 Service.prototype.__clean() 

Option name Type Description

Clean the service data, can only be used in test mode

__clean() {
	if (typeof(global.it) !== 'function') {
		throw Error("Only for test purpose")
	}
	return this.___cleanData();
}