Add event emitter methods to models.

This commit is contained in:
Ritchie Martori 2013-07-02 14:59:24 -07:00
parent 522291bf08
commit c8bfc5802a
1 changed files with 8 additions and 2 deletions

View File

@ -114,6 +114,12 @@ ModelBuilder.prototype.define = function defineClass(className, properties, sett
hiddenProperty(this, 'schema', schema || this.constructor.schema); hiddenProperty(this, 'schema', schema || this.constructor.schema);
}; };
// mix in EventEmitter
var events = new EventEmitter();
ModelClass.on = events.on.bind(events);
ModelClass.once = events.once.bind(events);
ModelClass.emit = events.emit.bind(events);
hiddenProperty(ModelClass, 'schema', schema); hiddenProperty(ModelClass, 'schema', schema);
hiddenProperty(ModelClass, 'modelName', className); hiddenProperty(ModelClass, 'modelName', className);
hiddenProperty(ModelClass, 'pluralModelName', pluralName || i8n.pluralize(className)); hiddenProperty(ModelClass, 'pluralModelName', pluralName || i8n.pluralize(className));
@ -370,7 +376,7 @@ ModelBuilder.prototype.copyModel = function copyModel(Master) {
*/ */
function hiddenProperty(where, property, value) { function hiddenProperty(where, property, value) {
Object.defineProperty(where, property, { Object.defineProperty(where, property, {
writable: false, writable: true,
enumerable: false, enumerable: false,
configurable: true, configurable: true,
value: value value: value