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

@ -109,10 +109,16 @@ ModelBuilder.prototype.define = function defineClass(className, properties, sett
buildSchema(className, properties); buildSchema(className, properties);
// every class can receive hash of data as optional param // every class can receive hash of data as optional param
var ModelClass = function ModelConstructor(data, schema) { var ModelClass = function ModelConstructor(data, schema) {
ModelBaseClass.apply(this, arguments); ModelBaseClass.apply(this, arguments);
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);
@ -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