Skip to content

Commit

Permalink
Extending override() with an optional third parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
avoidwork committed Sep 21, 2015
1 parent d2ff10a commit 50744db
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 9 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -521,11 +521,12 @@ store.map(function (value) {
});
```

**override( data[, type="records"] )**
**override( data[, type="records", fn] )**
_Promise_

Returns a `Promise` for the new state. This is meant to be used in a paired override of the indexes & records, such that
you can avoid the `Promise` based code path of a `batch()` insert or `load()`.
you can avoid the `Promise` based code path of a `batch()` insert or `load()`. Accepts an optional third parameter to perform the
transformation to simplify cross domain issues.

Example of mapping a DataStore:
```javascript
Expand Down
4 changes: 2 additions & 2 deletions lib/haro.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,11 +487,11 @@ class Haro {
return tuple.apply(tuple, result);
}

override (data, type = "records") {
override (data, type = "records", fn = undefined) {
let defer = deferred();

if (type === "indexes") {
this.indexes = this.transform(data);
this.indexes = this.transform(data, fn);
defer.resolve(true);
} else if (type === "records") {
this.data = new Map();
Expand Down
3 changes: 2 additions & 1 deletion lib/haro.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,11 +550,12 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
var _this6 = this;

var type = arguments.length <= 1 || arguments[1] === undefined ? "records" : arguments[1];
var fn = arguments.length <= 2 || arguments[2] === undefined ? undefined : arguments[2];

var defer = deferred();

if (type === "indexes") {
this.indexes = this.transform(data);
this.indexes = this.transform(data, fn);
defer.resolve(true);
} else if (type === "records") {
this.data = new Map();
Expand Down
2 changes: 1 addition & 1 deletion 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.

4 changes: 2 additions & 2 deletions src/haro.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,11 @@ class Haro {
return tuple.apply(tuple, result);
}

override (data, type = "records") {
override (data, type = "records", fn = undefined) {
let defer = deferred();

if (type === "indexes") {
this.indexes = this.transform(data);
this.indexes = this.transform(data, fn);
defer.resolve(true);
} else if (type === "records") {
this.data = new Map();
Expand Down

0 comments on commit 50744db

Please sign in to comment.