Permalink
Browse files

clean up Model#remove

  • Loading branch information...
1 parent f697135 commit 1662af1769fac69ceac75ce627f956c476c2eba0 @aheckmann aheckmann committed Aug 30, 2011
Showing with 12 additions and 12 deletions.
  1. +12 −12 lib/model.js
View
@@ -417,20 +417,20 @@ Model.prototype.reset = function reset () {
* @api public
*/
-Model.prototype.remove = function (fn) {
- if (this.removing || this.removed)
- return this;
+Model.prototype.remove = function remove (fn) {
+ if (this._removing) return this;
- if (!this.removing) {
- var promise = this.removing = new Promise(fn)
- , self = this;
+ var promise = this._removing = new Promise(fn)
+ , self = this;
- this.collection.remove({ _id: this._doc._id }, function (err) {
- if (err) return promise.error(err);
- promise.complete();
- self.emit('remove');
- });
- }
+ this.collection.remove({ _id: this._doc._id }, function (err) {
+ if (err) {
+ this._removing = null;
+ return promise.error(err);
+ }
+ promise.complete();
+ self.emit('remove');
+ });
return this;
};

0 comments on commit 1662af1

Please sign in to comment.