Skip to content

Commit

Permalink
Changing the signature of limit() to take max & offset paramete…
Browse files Browse the repository at this point in the history
…rs like MySQL syntax
  • Loading branch information
avoidwork committed Jul 2, 2015
1 parent ce8adaa commit d529014
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 25 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ do {
} while (!item.done);
```

**limit( start, offset )**
**limit( max, offset )**
_Tuple_

Returns a `Tuple` of double `Tuples` with the shape `[key, value]` for the corresponding range of records.
Expand All @@ -359,8 +359,8 @@ var store = haro(), ds1, ds2;
// Data is added
console.log(store.total); // >10
ds1 = store.limit(10, 0);
ds2 = store.limit(10, 10);
ds1 = store.limit(10); // [0-9]
ds2 = store.limit(10, 10); // [10-19]
console.log(ds1.length === ds2.length); // true
console.log(JSON.stringify(ds1[0][1]) === JSON.stringify(ds2[0][1])); // false
Expand Down
10 changes: 5 additions & 5 deletions lib/haro.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @copyright 2015
* @license BSD-3-Clause
* @link http://haro.rocks
* @version 1.2.3
* @version 1.3.0
*/
"use strict";

Expand Down Expand Up @@ -258,9 +258,9 @@ class Haro {
return this.data.keys();
}

limit (start=0, offset=0) {
let i = start,
nth = start + offset,
limit (max=1, offset=0) {
let i = offset,
nth = max + offset,
list = [],
k;

Expand Down Expand Up @@ -525,7 +525,7 @@ function factory (data=null, config={}, indexes=[]) {
return new Haro(data, config, indexes);
}

factory.version = "1.2.3";
factory.version = "1.3.0";

// Node, AMD & window supported
if (typeof exports !== "undefined") {
Expand Down
10 changes: 5 additions & 5 deletions lib/haro.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @copyright 2015
* @license BSD-3-Clause
* @link http://haro.rocks
* @version 1.2.3
* @version 1.3.0
*/
"use strict";

Expand Down Expand Up @@ -293,11 +293,11 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
}, {
key: "limit",
value: function limit() {
var start = arguments[0] === undefined ? 0 : arguments[0];
var max = arguments[0] === undefined ? 1 : arguments[0];
var offset = arguments[1] === undefined ? 0 : arguments[1];

var i = start,
nth = start + offset,
var i = offset,
nth = max + offset,
list = [],
k = undefined;

Expand Down Expand Up @@ -603,7 +603,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
return new Haro(data, config, indexes);
}

factory.version = "1.2.3";
factory.version = "1.3.0";

// Node, AMD & window supported
if (typeof exports !== "undefined") {
Expand Down
2 changes: 1 addition & 1 deletion lib/haro.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/haro.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "haro",
"version": "1.2.3",
"version": "1.3.0",
"description": "Harō is a modern immutable DataStore using Maps, Sets, Promises, & Tuples",
"main": "lib/haro.js",
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions src/haro.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ class Haro {
return this.data.keys();
}

limit (start=0, offset=0) {
let i = start,
nth = start + offset,
limit (max=1, offset=0) {
let i = offset,
nth = max + offset,
list = [],
k;

Expand Down
13 changes: 7 additions & 6 deletions test/haro_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,17 @@ exports["create (batch)"] = {
test: function (test) {
var self = this;

test.expect(11);
test.expect(12);
test.equal(this.store.total, 0, "Should be '0'");
test.equal(this.store.data.size, 0, "Should be '0'");
this.store.batch(data, "set").then(function () {
test.equal(self.store.total, 6, "Should be '6'");
test.equal(self.store.data.size, 6, "Should be '6'");
test.equal(self.store.registry.length, 6, "Should be '6'");
test.equal(self.store.limit(2, 1)[0][0], self.store.get(self.store.registry[2])[0], "Should be a match");
test.equal(self.store.limit(2, 2)[1][0], self.store.get(self.store.registry[3])[0], "Should be a match");
test.equal(self.store.limit(10, 5).length, 0, "Should be '0'");
test.equal(self.store.limit(1)[0][0], self.store.get(self.store.registry[0])[0], "Should be a match");
test.equal(self.store.limit(2)[1][0], self.store.get(self.store.registry[1])[0], "Should be a match");
test.equal(self.store.limit(1, 1)[0][0], self.store.get(self.store.registry[1])[0], "Should be a match");
test.equal(self.store.limit(5, 10).length, 0, "Should be '0'");
test.equal(self.store.filter(function (i) {
return /decker/i.test(i.name);
}).length, 1, "Should be '1'");
Expand Down Expand Up @@ -168,7 +169,7 @@ exports["read (indexed)"] = {
test.equal(self.store.find({gender: "male", age: 20}).length, 1, "Should be `1`");
test.equal(self.store.find({age: 50}).length, 0, "Should be `0`");
test.equal(self.store.find({agez: 1}).length, 0, "Should be `0`");
test.equal(self.store.limit(0, 3)[2][1].guid, "f34d994b-24eb-4553-adf7-8f61e7ef8741", "Should be `f34d994b-24eb-4553-adf7-8f61e7ef8741`");
test.equal(self.store.limit(3)[2][1].guid, "f34d994b-24eb-4553-adf7-8f61e7ef8741", "Should be `f34d994b-24eb-4553-adf7-8f61e7ef8741`");
return args;
}, function (e) {
throw e;
Expand All @@ -179,7 +180,7 @@ exports["read (indexed)"] = {
}).then(function () {
test.equal(self.store.find({age: 20, gender: "male"}).length, 0, "Should be `0`");
test.equal(self.store.indexes.get("age").get(20).size, 1, "Should be `1`");
test.equal(self.store.limit(0, 3)[2][1].guid, "a94c8560-7bfd-42ec-a759-cbd5899b33c0", "Should be `a94c8560-7bfd-42ec-a759-cbd5899b33c0`");
test.equal(self.store.limit(3)[2][1].guid, "a94c8560-7bfd-42ec-a759-cbd5899b33c0", "Should be `a94c8560-7bfd-42ec-a759-cbd5899b33c0`");
test.done();
}, function (e) {
console.log(e.stack);
Expand Down

0 comments on commit d529014

Please sign in to comment.