Add event emitter methods to models.
This commit is contained in:
parent
522291bf08
commit
c8bfc5802a
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue