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 camelize = require('underscore.string/camelize');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var util = require('util');
|
var util = require('util');
|
||||||
|
var EventEmitter = require('events');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The `App` object represents a Loopback application.
|
* 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);
|
var handler = this._handlers[type] = remotes.handler(type, options);
|
||||||
|
|
||||||
remotes.classes().forEach(function(sharedClass) {
|
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;
|
return handler;
|
||||||
|
@ -587,29 +590,37 @@ app.listen = function(cb) {
|
||||||
|
|
||||||
app.controller = function(ctor, options) {
|
app.controller = function(ctor, options) {
|
||||||
var controller = new SharedController(ctor);
|
var controller = new SharedController(ctor);
|
||||||
app.remotes().addClass(wrapper.sharedClass);
|
this.remotes().addClass(controller.sharedClass);
|
||||||
app.controllers[ctor.name] = wrapper;
|
app.controllers().push(controller);
|
||||||
return wrapper;
|
return controller;
|
||||||
|
};
|
||||||
|
|
||||||
|
app.controllers = function() {
|
||||||
|
return this._controllers || (this._controllers = []);
|
||||||
};
|
};
|
||||||
|
|
||||||
function SharedController(ctor, options) {
|
function SharedController(ctor, options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
this.name = ctor.name;
|
this.name = ctor.name;
|
||||||
this.ctor = ctor;
|
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) {
|
SharedController.prototype.remoteMethod = function(name, options) {
|
||||||
if (options.isStatic === undefined) {
|
options.isStatic = true;
|
||||||
var m = name.match(/^prototype\.(.*)$/);
|
|
||||||
options.isStatic = !m;
|
|
||||||
name = options.isStatic ? name : m[1];
|
|
||||||
}
|
|
||||||
this.sharedClass.defineMethod(name, options);
|
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 */
|
/* END CONTROLLER CODE */
|
||||||
|
|
Loading…
Reference in New Issue