Permalink
Browse files

add vars at beginning of function

  • Loading branch information...
1 parent 8d9bcc1 commit 0872248481204dd8f607e1a5cfb57a0eb7345204 @crcn crcn committed Apr 12, 2012
Showing with 15 additions and 14 deletions.
  1. +2 −1 src/common/abstract/cursor.js
  2. +2 −1 src/common/chainable.js
  3. +2 −3 src/common/collection.js
  4. +9 −9 src/common/drivers/memory/cursor.js
@@ -6,10 +6,11 @@ module.exports = structr({
/**
*/
- __construct: function(collection, selector, ModelClass) {
+ __construct: function(collection, selector, options, ModelClass) {
this.selector = selector;
this.collection = collection;
this._ModelClass = ModelClass;
+ this.options = options || {};
},
/**
@@ -60,7 +60,8 @@ module.exports = structr(EventEmitter, {
"_wrap": function() {
var args = arguments, self = this;
return function() {
- for(var i 0, n = args.length; i < n; i++) {
+ var i = 0;
+ for(; n = args.length; i < n; i++) {
args[i].apply(self, arguments);
}
}
@@ -11,9 +11,8 @@
*/
"override __construct": function(db, name) {
- this._super();
-
var self = this;
+ this._super();
//wait for the DB to be ready before starting
this.next(function() {
@@ -36,7 +35,7 @@
"find": function(selector, options, next) {
if(!next) {
-
+
}
}
@@ -8,7 +8,6 @@ var Cursor = require("../../abstract/cursor").extend({
"override __construct": function() {
this._super.apply(this);
- this._options = {};
this._position = 0;
this._sift = sift(this.selector);
@@ -28,7 +27,7 @@ var Cursor = require("../../abstract/cursor").extend({
sort = key;
}
- this._options.sort = sort;
+ this.options.sort = sort;
return this;
},
@@ -37,15 +36,15 @@ var Cursor = require("../../abstract/cursor").extend({
*/
limit: function(count) {
- this._options.limit = count;
+ this.options.limit = count;
return this;
},
/**
*/
skip: function(count) {
- this._options.skip = count;
+ this.options.skip = count;
this._position = count;
return this;
},
@@ -54,14 +53,13 @@ var Cursor = require("../../abstract/cursor").extend({
*/
rewind: function() {
- this._position = this._options.skip || 0;
+ this._position = this.options.skip || 0;
},
/**
*/
_nextObject: function(fn) {
-
var self = this;
self._all(function(err, sifted) {
@@ -74,12 +72,14 @@ var Cursor = require("../../abstract/cursor").extend({
_all: function(fn) {
+ var sifted;
+
//TODO - async chunk
if(this._sifted) return fn(null, this._sifted);
- var sifted = this._sifted = this._sort(this._sift(this.collection.target));
+ sifted = this._sifted = this._sort(this._sift(this.collection.target));
- if(this._options.limit && sifted.length > this._options.limit) {
- sifted = sifted.splice(0, this._options.limit);
+ if(this.options.limit && sifted.length > this._options.limit) {
+ sifted = sifted.splice(0, this.options.limit);
}
fn(null, sifted);

0 comments on commit 0872248

Please sign in to comment.