|
|
@@ -6,19 +6,21 @@
|
|
|
**/
|
|
|
var klass = module.exports = function Cursor(items){
|
|
|
if (!(items instanceof Array)) throw new Error("arg `items` must be an Array");
|
|
|
- this.cachedData = items.slice(0); // keep a copy
|
|
|
+ this.cachedData = items.slice(0); // keep a copy so array changes when using async doc srcs do not cause side effects
|
|
|
+ this.length = items.length;
|
|
|
+ this.offset = 0;
|
|
|
}, base = Object, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
|
|
|
|
|
|
proto.ok = function ok(){
|
|
|
- return this.cachedData.length > 0 || this.hasOwnProperty("curr");
|
|
|
+ return (this.offset < this.length) || this.hasOwnProperty("curr");
|
|
|
};
|
|
|
|
|
|
proto.advance = function advance(){
|
|
|
- if (this.cachedData.length === 0){
|
|
|
+ if (this.offset >= this.length){
|
|
|
delete this.curr;
|
|
|
return false;
|
|
|
}
|
|
|
- this.curr = this.cachedData.shift();
|
|
|
+ this.curr = this.cachedData[this.offset++];
|
|
|
return this.curr;
|
|
|
};
|
|
|
|