Skip to content

Commit

Permalink
Wrong behavior on non-matches (oops)
Browse files Browse the repository at this point in the history
  • Loading branch information
avoidwork committed Apr 2, 2018
1 parent de0dcd6 commit 21071f0
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 45 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1016,9 +1016,7 @@ store.batch(data, 'set').then(function () {
**where(predicate)**
_Array_

Performs a `find()` on the first key of `predicate`, and then a `filter()` on the remaining keys via a generated `Function`.

Ideal when dealing with a composite index which contains an `Array` of values, which would make matching on a single value impossible when using `find()`
Ideal for when dealing with a composite index which contains an `Array` of values, which would make matching on a single value impossible when using `find()`.

```javascript
const store = haro(null, {key: 'guid', index: ['name']}),
Expand Down
8 changes: 4 additions & 4 deletions lib/haro.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @author Jason Mulligan <jason.mulligan@avoidwork.com>
* @copyright 2018
* @license BSD-3-Clause
* @version 4.2.0
* @version 4.2.1
*/
"use strict";

Expand Down Expand Up @@ -1068,10 +1068,10 @@

result = this.filter(new Function("a", `return (${conditions.join(") && (")});`), true);
} else {
result = this.dump();
result = [];
}
} else {
result = this.dump();
result = [];
}

return result;
Expand All @@ -1093,7 +1093,7 @@
}

factory.transform = cast;
factory.version = "4.2.0";
factory.version = "4.2.1";

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

Large diffs are not rendered by default.

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-lock.json

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

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": "4.2.0",
"version": "4.2.1",
"description": "Harō is a modern immutable DataStore",
"main": "lib/haro.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions src/haro.js
Original file line number Diff line number Diff line change
Expand Up @@ -751,10 +751,10 @@

result = this.filter(new Function("a", `return (${conditions.join(") && (")});`), true);
} else {
result = this.dump();
result = [];
}
} else {
result = this.dump();
result = [];
}

return result;
Expand Down
64 changes: 33 additions & 31 deletions test/offline.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ exports.create = {
done();
},
test: function (test) {
var self = this;
const self = this;

test.expect(6);
test.equal(this.store.total, 0, "Should be '0'");
Expand All @@ -45,7 +45,7 @@ exports["create (batch)"] = {
done();
},
test: function (test) {
var self = this;
const self = this;

test.expect(13);
test.equal(this.store.total, 0, "Should be '0'");
Expand Down Expand Up @@ -85,7 +85,7 @@ exports["update (batch)"] = {
done();
},
test: function (test) {
var self = this;
const self = this;

test.expect(17);
test.equal(this.store.total, 0, "Should be '0'");
Expand Down Expand Up @@ -135,11 +135,11 @@ exports["read (valid)"] = {
done();
},
test: function (test) {
var self = this;
const self = this;

test.expect(5);
this.store.set(null, data[0]).then(function (arg) {
var record = self.store.get(arg[0]);
const record = self.store.get(arg[0]);

test.equal(self.store.total, 1, "Should be '1'");
test.equal(self.store.size, 1, "Should be '1'");
Expand All @@ -159,7 +159,7 @@ exports["read (invalid)"] = {
done();
},
test: function (test) {
var self = this;
const self = this;

test.expect(4);
this.store.set(null, data[0]).then(function () {
Expand All @@ -180,7 +180,7 @@ exports["read (raw/immutable)"] = {
done();
},
test: function (test) {
var self = this;
const self = this;

test.expect(1);
this.store.set(null, data[0]).then(function (arg) {
Expand All @@ -199,7 +199,7 @@ exports["read (indexed)"] = {
done();
},
test: function (test) {
var self = this;
const self = this;

test.expect(11);
this.store.batch(data, "set").then(function (args) {
Expand Down Expand Up @@ -236,7 +236,7 @@ exports["read (toArray)"] = {
done();
},
test: function (test) {
var self = this;
const self = this;

test.expect(4);
this.store.batch(data, "set").then(function () {
Expand All @@ -257,7 +257,7 @@ exports["read (toObject)"] = {
done();
},
test: function (test) {
var self = this;
const self = this;

test.expect(4);
this.store.batch(data, "set").then(function () {
Expand All @@ -278,7 +278,7 @@ exports["read (sort)"] = {
done();
},
test: function (test) {
var self = this;
const self = this;

test.expect(1);
this.store.batch(data, "set").then(function () {
Expand All @@ -303,7 +303,7 @@ exports["read (sortBy)"] = {
done();
},
test: function (test) {
var self = this;
const self = this;

test.expect(1);
this.store.batch(data, "set").then(function () {
Expand All @@ -321,12 +321,12 @@ exports["read (search - un-indexed)"] = {
done();
},
test: function (test) {
var self = this,
const self = this,
regex = new RegExp(".*de.*", "i");

test.expect(1);
this.store.batch(data, "set").then(function () {
var result = self.store.search(regex, "name");
const result = self.store.search(regex, "name");

test.equal(result.length, 0, "Should be '0'");
test.done();
Expand All @@ -342,14 +342,14 @@ exports["read (search - indexed)"] = {
done();
},
test: function (test) {
var self = this,
const self = this,
regex = new RegExp(".*de.*", "i");

test.expect(6);
this.store.batch(data, "set").then(function () {
var result1 = self.store.search(regex);
var result2 = self.store.search(20, "age");
var result3 = self.store.search(/velit/, "tags");
const result1 = self.store.search(regex);
const result2 = self.store.search(20, "age");
const result3 = self.store.search(/velit/, "tags");

test.equal(result1.length, 2, "Should be '2'");
test.equal(result1[0][1].name, "Decker Merrill", "Should be 'Decker Merrill'");
Expand Down Expand Up @@ -447,7 +447,7 @@ exports.update = {
done();
},
test: function (test) {
var self = this;
const self = this;

test.expect(3);
this.store.set(null, data[0]).then(function (arg) {
Expand All @@ -474,7 +474,7 @@ exports.delete = {
done();
},
test: function (test) {
var self = this;
const self = this;

test.expect(4);
this.store.set(null, data[0]).then(function (arg) {
Expand Down Expand Up @@ -502,7 +502,7 @@ exports["delete (batch)"] = {
done();
},
test: function (test) {
var self = this;
const self = this;

test.expect(4);
this.store.batch(data, "set").then(function (arg) {
Expand Down Expand Up @@ -530,11 +530,11 @@ exports["dump (indexes)"] = {
done();
},
test: function (test) {
var self = this;
const self = this;

test.expect(2);
this.store.batch(data, "set").then(function () {
var ldata = self.store.dump("indexes");
const ldata = self.store.dump("indexes");

test.equal(Object.keys(ldata).length, 3, "Should be a match");
test.equal(Object.isFrozen(ldata), false, "Should be 'false'");
Expand All @@ -551,11 +551,11 @@ exports["dump (records)"] = {
done();
},
test: function (test) {
var self = this;
const self = this;

test.expect(2);
this.store.batch(data, "set").then(function () {
var ldata = self.store.dump();
const ldata = self.store.dump();

test.equal(ldata.length, data.length, "Should be a match");
test.equal(Object.isFrozen(ldata), false, "Should be 'false'");
Expand All @@ -572,7 +572,7 @@ exports["offload (indexes)"] = {
done();
},
test: function (test) {
var self = this;
const self = this;

test.expect(3);
this.store.offload(data).then(function (args) {
Expand Down Expand Up @@ -618,7 +618,7 @@ exports["override (indexes)"] = {
done();
},
test: function (test) {
var self = this;
const self = this;

test.expect(6);
test.equal(self.store.indexes.size, 0, "Should be a '0'");
Expand All @@ -645,7 +645,7 @@ exports["override (records)"] = {
done();
},
test: function (test) {
var self = this;
const self = this;

test.expect(4);
this.store.override(data, "records").then(function () {
Expand All @@ -662,15 +662,17 @@ exports["override (records)"] = {

exports.where = {
setUp: function (done) {
this.store = haro(null, {key: "guid", logging: false, index: ["name", "company"]});
this.store = haro(null, {key: "guid", logging: false, index: ["name", "company", "tags", "company|tags"]});
done();
},
test: function (test) {
var self = this;
const self = this;

test.expect(1);
test.expect(3);
this.store.batch(data, "set").then(function () {
test.equal(self.store.where({company: "Insectus", tags: "occaecat"}).length, 1, "Should be '1'");
test.equal(self.store.where({company: "Insectus", tags: "aaaaa"}).length, 0, "Should be '0'");
test.equal(self.store.where({}).length, 0, "Should be '0'");
test.done();
}, function () {
test.done();
Expand Down

0 comments on commit 21071f0

Please sign in to comment.