Add service method
This commit is contained in:
parent
f45e241f4b
commit
3a420187e9
|
@ -25,6 +25,21 @@ app.remotes = function () {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Expose an object or Class remotely.
|
||||
*
|
||||
* @param {String} name The remote namespace (eg. url base)
|
||||
* @param {Object|Function} obj The object to remote
|
||||
*/
|
||||
|
||||
app.remote = function (name, obj) {
|
||||
// add the object to the remote exports
|
||||
this.remotes().exports[name] = obj;
|
||||
|
||||
// clear the handlers cache
|
||||
this._handlers = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a route by reference.
|
||||
*/
|
||||
|
@ -70,10 +85,32 @@ app.model = function (Model) {
|
|||
}
|
||||
|
||||
// add to the remote exports
|
||||
remotes.exports[Model.pluralModelName] = Model;
|
||||
this.remote(Model.pluralModelName, Model);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all exposed models.
|
||||
*/
|
||||
|
||||
app.models = function () {
|
||||
return this._models;
|
||||
}
|
||||
|
||||
/**
|
||||
* Expose a service.
|
||||
*
|
||||
* @param {String} name
|
||||
* @param {Service} service
|
||||
*/
|
||||
|
||||
app.service = function (name, service) {
|
||||
this._services.push(service);
|
||||
service.shared = true;
|
||||
|
||||
// clear the handlers cache
|
||||
this._handlers = {};
|
||||
service.app = this;
|
||||
|
||||
// add to the remote exports
|
||||
this.remote(name, service);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue