Skip to content

Commit

Permalink
Removing truthy condition from get() such that the output is consis…
Browse files Browse the repository at this point in the history
…tent in shape (breaking change for invalid key & tuple result), updating "invalid" read tests
  • Loading branch information
avoidwork committed May 7, 2020
1 parent 476d5d0 commit 1cd84f5
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
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 2020
* @license BSD-3-Clause
* @version 7.0.2
* @version 8.0.0
*/
"use strict";

Expand Down Expand Up @@ -249,7 +249,7 @@
get (key, raw = false) {
const result = clone(this.data.get(key) || null);

return result && !raw ? this.list(key, result) : result;
return raw ? result : this.list(key, result);
}

has (key, map = this.data) {
Expand Down Expand Up @@ -472,7 +472,7 @@
return obj;
}

factory.version = "7.0.2";
factory.version = "8.0.0";

// Node, AMD & window supported
if (typeof exports !== "undefined") {
Expand Down
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": "7.0.2",
"version": "8.0.0",
"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 @@ -141,7 +141,7 @@
get (key, raw = false) {
const result = clone(this.data.get(key) || null);

return result && !raw ? this.list(key, result) : result;
return raw ? result : this.list(key, result);
}

has (key, map = this.data) {
Expand Down
7 changes: 5 additions & 2 deletions test/offline.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,14 @@ exports["read (invalid)"] = {
test: function (test) {
const self = this;

test.expect(3);
test.expect(6);
this.store.set(null, data[0]).then(function () {
test.equal(self.store.size, 1, "Should be '1'");
test.equal(self.store.data.size, 1, "Should be '1'");
test.equal(self.store.get("abc"), undefined, "Should be 'undefined'");
test.equal(self.store.get("abc") instanceof Array, true, "Should be 'true'");
test.equal(self.store.get("abc")[0], "abc", "Should be 'abc'");
test.equal(self.store.get("abc")[1], null, "Should be 'null'");
test.equal(self.store.get("abc", true), null, "Should be 'null'");
test.done();
}, function () {
test.done();
Expand Down

0 comments on commit 1cd84f5

Please sign in to comment.