Skip to content

Commit

Permalink
Changing the signature of map() to accept a second raw parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
avoidwork committed Oct 24, 2016
1 parent a865347 commit d24f4b4
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -598,10 +598,10 @@ _Promise_
Loads the DataStore, or a record from a specific persistent storage & updates the DataStore. The DataStore will be cleared
prior to loading if `key` is omitted.

**map(callbackFn)**
**map(callbackFn, raw=false)**
_Tuple_

Returns a `Tuple` of the returns of `callbackFn(value, key)`.
Returns a `Tuple` of the returns of `callbackFn(value, key)`. If `raw` is `true` an `Array` is returned.

Example of mapping a DataStore:
```javascript
Expand Down
8 changes: 4 additions & 4 deletions lib/haro.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -688,14 +688,14 @@ class Haro {
});
}

map (fn) {
map (fn, raw = false) {
let result = [];

this.forEach((value, key) => {
result.push(fn(value, key));
});

return tuple.apply(tuple, result);
return !raw ? tuple.apply(tuple, result) : result;
}

offload (data, cmd = "index", index = this.index) {
Expand Down Expand Up @@ -751,8 +751,8 @@ class Haro {
this.indexes = this.transform(data, fn);
defer.resolve(true);
} else if (type === "records") {
this.data = new Map();
this.registry = [];
this.data.clear();
this.registry.length = 0;
data.forEach(datum => {
let key = datum[this.key] || uuid();

Expand Down
8 changes: 5 additions & 3 deletions lib/haro.js
Original file line number Diff line number Diff line change
Expand Up @@ -764,13 +764,15 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
}, {
key: "map",
value: function map(fn) {
var raw = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;

var result = [];

this.forEach(function (value, key) {
result.push(fn(value, key));
});

return tuple.apply(tuple, result);
return !raw ? tuple.apply(tuple, result) : result;
}
}, {
key: "offload",
Expand Down Expand Up @@ -848,8 +850,8 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
this.indexes = this.transform(data, fn);
defer.resolve(true);
} else if (type === "records") {
this.data = new Map();
this.registry = [];
this.data.clear();
this.registry.length = 0;
data.forEach(function (datum) {
var key = datum[_this7.key] || uuid();

Expand Down
Loading

0 comments on commit d24f4b4

Please sign in to comment.