Skip to content

Commit

Permalink
Refactoring where() such that the predicate does not have to be a i…
Browse files Browse the repository at this point in the history
…ndexed values, e.g. an aware `filter()`
  • Loading branch information
avoidwork committed Sep 24, 2018
1 parent 8511953 commit 584779e
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ store.batch(data, 'set').then(function () {
**where(predicate[, raw=false])**
_Array_

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()`.
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()`. Predicate can include fields which are not indexed.

```javascript
const store = haro(null, {key: 'guid', index: ['name', 'name|age', 'age']}),
Expand Down
6 changes: 3 additions & 3 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.3.2
* @version 4.3.3
*/
"use strict";

Expand Down Expand Up @@ -1060,7 +1060,7 @@
}

where (predicate, raw = false) {
const keys = this.index.filter(i => i in predicate);
const keys = Object.keys(predicate);

return keys.length > 0 ? this.filter(new Function("a", `return (${keys.map(i => {
const arg = typeof predicate[i] === "string" ? `'${predicate[i]}'` : predicate[i];
Expand All @@ -1085,7 +1085,7 @@
}

factory.transform = cast;
factory.version = "4.3.2";
factory.version = "4.3.3";

// 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.3.2",
"version": "4.3.3",
"description": "Harō is a modern immutable DataStore",
"main": "lib/haro.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/haro.js
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@
}

where (predicate, raw = false) {
const keys = this.index.filter(i => i in predicate);
const keys = Object.keys(predicate);

return keys.length > 0 ? this.filter(new Function("a", `return (${keys.map(i => {
const arg = typeof predicate[i] === "string" ? `'${predicate[i]}'` : predicate[i];
Expand Down

1 comment on commit 584779e

@avoidwork
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This caused a regression in a product; likely needs to be reverted.

Please sign in to comment.