Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

issues #13, #14 and #15 #16

Open
wants to merge 1 commit into from

2 participants

@ramitos

Issue #13

I didn't found any reference to the variable value, so i just deleted and everything worked as expected.

Issue #14

Instead of returning a stream, it calls the callback whith the stream as parameter.

So, insted of

var stream = article.find({date: {$range: {$start: null, $end: null}}}).stream();

stream.on('record', function(record) {
  console.log(record);
});
stream.on('error', function(err) {
  throw(err);
});
stream.on('end', function() {
  console.log('ended');
});

it should now be

article.find({date: {$range: {$start: null, $end: null}}}).stream(function (stream) {   
    stream.on('record', function(record) {
      console.log(record);
    });
    stream.on('error', function(err) {
      throw(err);
    });
    stream.on('end', function() {
      console.log('ended');
    });
});

Issue #15

Tried array.map and proccess.nextTick to prevent the RangeError, but only worked using async's forEachSeries

@xasima

Please change in alfred/meta/model.js lines 158 - 171
from

Model.prototype._delete = function(id, callback) {
  this.collection.destroy(id, function(err) {
    if (err) { self._error(err); return; }
    callback();
  });
};

Model.prototype.delete = function(id, callback) {
  var self = this;
  this.promises.done(function() {
    self.delete(id, callback);
  });
};

to

Model.prototype._delete = function(id, callback) {
  this.collection.destroy(id, function(err) {
    if (err) { self._error(err); return; }
    callback();
  });
};

Model.prototype.delete = function(id, callback) {
  var self = this;
  this.promises.done(function() {
    self._delete(id, callback);
  });
};

Underscore for _delete should be added at 168-169 line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 4, 2012
  1. issues #13, #14 and #15

    Sérgio Ramos authored
This page is out of date. Refresh to see the latest.
Showing with 13 additions and 6 deletions.
  1. +2 −3 lib/alfred/meta/model/model.js
  2. +11 −3 lib/alfred/util/promises.js
View
5 lib/alfred/meta/model/model.js
@@ -216,13 +216,12 @@ Model.prototype.find = function(query) {
});
stream.on('record', function(key, record) {
- value.id = key;
var doc = self.instantiate(record.value);
doc.id = record.key;
stream.emit('document', doc);
});
-
- return stream;
+
+ callback(stream);
});
});
return finder;
View
14 lib/alfred/util/promises.js
@@ -1,3 +1,5 @@
+var async = require('async');
+
var Promises = function() {
this.pendingCount = 0;
this.doneCallbacks = [];
@@ -13,10 +15,16 @@ Promises.prototype.add = function(promise) {
promise(function() {
self.pendingCount --;
if (self.pendingCount === 0) {
- while (self.doneCallbacks.length > 0) {
- cb = self.doneCallbacks.splice(0, 1)[0];
+
+ async.forEachSeries(self.doneCallbacks, function(callback, cb) {
+ self.doneCallbacks.splice(0, 1);
+ callback();
cb();
- }
+ }, function(err) {
+ if(err) {
+ throw new Error();
+ }
+ });
}
});
};
Something went wrong with that request. Please try again.