Skip to content

Commit

Permalink
Clean up for #1351
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Dec 15, 2014
1 parent def0afe commit f299d9f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 30 deletions.
5 changes: 3 additions & 2 deletions lib/browserDocument.js
Expand Up @@ -63,6 +63,7 @@ function Document (obj, schema, fields, skipId, skipInit) {
this.$__setSchema(schema);

this.$__ = new InternalCache;
this.$__.emitter = new EventEmitter();
this.isNew = true;
this.errors = undefined;

Expand Down Expand Up @@ -101,9 +102,9 @@ function Document (obj, schema, fields, skipId, skipInit) {
}

/*!
* Inherit from EventEmitter.
* Inherit from the NodeJS document
*/
Document.prototype = Object.create( NodeJSDocument.prototype );
Document.prototype = Object.create(NodeJSDocument.prototype);
Document.prototype.constructor = Document;


Expand Down
38 changes: 10 additions & 28 deletions lib/document.js
Expand Up @@ -77,35 +77,17 @@ function Document (obj, fields, skipId) {
}

/*!
* Inherit from EventEmitter.
* Document exposes the NodeJS event emitter API, so you can use
* `on`, `once`, etc.
*/
Document.prototype.on = function() {
return this.$__.emitter.on.apply(this.$__.emitter, arguments);
};

Document.prototype.once = function() {
return this.$__.emitter.once.apply(this.$__.emitter, arguments);
};

Document.prototype.emit = function() {
return this.$__.emitter.emit.apply(this.$__.emitter, arguments);
};

Document.prototype.listeners = function() {
return this.$__.emitter.listeners.apply(this.$__.emitter, arguments);
};

Document.prototype.removeListener = function() {
return this.$__.emitter.removeListener.apply(this.$__.emitter, arguments);
};

Document.prototype.setMaxListeners = function() {
return this.$__.emitter.setMaxListeners.apply(this.$__.emitter, arguments);
};

Document.prototype.removeAllListeners = function() {
return this.$__.emitter.removeAllListeners.apply(this.$__.emitter, arguments);
};
utils.each(
['on', 'once', 'emit', 'listeners', 'removeListener', 'setMaxListeners',
'removeAllListeners'],
function(emitterFn) {
Document.prototype[emitterFn] = function() {
return this.$__.emitter[emitterFn].apply(this.$__.emitter, arguments);
};
});

Document.prototype.constructor = Document;

Expand Down

0 comments on commit f299d9f

Please sign in to comment.