Initialize controller
This commit is contained in:
parent
a9696aeaf8
commit
b46b336775
|
@ -12,6 +12,7 @@ var classify = require('underscore.string/classify');
|
|||
var camelize = require('underscore.string/camelize');
|
||||
var path = require('path');
|
||||
var util = require('util');
|
||||
var EventEmitter = require('events');
|
||||
|
||||
/**
|
||||
* The `App` object represents a Loopback application.
|
||||
|
@ -284,7 +285,9 @@ app.handler = function(type, options) {
|
|||
var handler = this._handlers[type] = remotes.handler(type, options);
|
||||
|
||||
remotes.classes().forEach(function(sharedClass) {
|
||||
sharedClass.ctor.emit('mounted', app, sharedClass, remotes);
|
||||
if (sharedClass.name !== 'ctrl') {
|
||||
sharedClass.ctor.emit('mounted', app, sharedClass, remotes);
|
||||
}
|
||||
});
|
||||
|
||||
return handler;
|
||||
|
@ -587,29 +590,37 @@ app.listen = function(cb) {
|
|||
|
||||
app.controller = function(ctor, options) {
|
||||
var controller = new SharedController(ctor);
|
||||
app.remotes().addClass(wrapper.sharedClass);
|
||||
app.controllers[ctor.name] = wrapper;
|
||||
return wrapper;
|
||||
this.remotes().addClass(controller.sharedClass);
|
||||
app.controllers().push(controller);
|
||||
return controller;
|
||||
};
|
||||
|
||||
app.controllers = function() {
|
||||
return this._controllers || (this._controllers = []);
|
||||
};
|
||||
|
||||
function SharedController(ctor, options) {
|
||||
options = options || {};
|
||||
this.name = ctor.name;
|
||||
this.ctor = ctor;
|
||||
this.sharedClass = new SharedClass(this.name, ctor, options);
|
||||
util.inherits(ctor, EventEmitter);
|
||||
this.sharedClass = new RemoteObjects.SharedClass(this.name, ctor, options);
|
||||
};
|
||||
|
||||
SharedController.remoteMethod = function(name, options) {
|
||||
if (options.isStatic === undefined) {
|
||||
var m = name.match(/^prototype\.(.*)$/);
|
||||
options.isStatic = !m;
|
||||
name = options.isStatic ? name : m[1];
|
||||
}
|
||||
SharedController.prototype.remoteMethod = function(name, options) {
|
||||
options.isStatic = true;
|
||||
this.sharedClass.defineMethod(name, options);
|
||||
};
|
||||
|
||||
SharedController.disableRemoteMethod = function() {
|
||||
|
||||
SharedController.prototype.disableRemoteMethod = function(name, isStatic) {
|
||||
this.sharedClass.disableMethod(name, isStatic || false);
|
||||
};
|
||||
|
||||
// TODO
|
||||
// need to add the EventEmitter to the constructor of the controller
|
||||
// function ctrl() {
|
||||
// // EventEmitter.call(this);
|
||||
// };
|
||||
// util.inherits(ctrl, EventEmitter);
|
||||
|
||||
/* END CONTROLLER CODE */
|
||||
|
|
Loading…
Reference in New Issue