Skip to content

Commit

Permalink
Changing the signature of toArray() to remove decoration of the rec…
Browse files Browse the repository at this point in the history
…ord keys in the resulting `Array` because it shouldn't happen
  • Loading branch information
avoidwork committed Oct 25, 2016
1 parent 78be7cc commit 37eaac5
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 194 deletions.
76 changes: 12 additions & 64 deletions lib/haro.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @copyright 2016
* @license BSD-3-Clause
* @link https://github.com/avoidwork/haro
* @version 3.0.1
* @version 3.0.2
*/
"use strict";

Expand Down Expand Up @@ -1129,72 +1129,20 @@ class Haro {
}

toArray (data, frozen = true) {
let key = this.key,
fn, result;
let result;

if (data) {
fn = (() => {
if (key) {
return function (a, b) {
let obj = clone(b[1]);

if (obj[key] === undefined) {
obj[key] = clone(b[0]);
}

if (frozen) {
Object.freeze(obj);
}

a.push(obj);

return a;
};
} else {
return function (a, b) {
let obj = clone(b[1]);

if (frozen) {
Object.freeze(obj);
}

a.push(obj);

return a;
};
}
})();
result = data.reduce(fn, []);
result = data.map(i => {
return frozen ? i[1] : clone(i[1]);
});
} else {
fn = (() => {
if (key) {
return function (val, id) {
let obj = clone(val);
result = this.limit(0, this.total, true);

if (obj[key] === undefined) {
obj[key] = clone(id);
}

if (frozen) {
Object.freeze(obj);
}

result.push(obj);
};
} else {
return function (val) {
let obj = clone(val);

if (frozen) {
Object.freeze(obj);
}

result.push(obj);
};
}
})();
result = [];
this.forEach(fn);
if (frozen) {
result.forEach(i => {
Object.freeze(i);
});
}
}

return frozen ? Object.freeze(result) : result;
Expand Down Expand Up @@ -1303,7 +1251,7 @@ function factory (data = null, config = {}, indexes = []) {
}

factory.transform = cast;
factory.version = "3.0.1";
factory.version = "3.0.2";

// Node, AMD & window supported
if (typeof exports !== "undefined") {
Expand Down
77 changes: 12 additions & 65 deletions lib/haro.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @copyright 2016
* @license BSD-3-Clause
* @link https://github.com/avoidwork/haro
* @version 3.0.1
* @version 3.0.2
*/
"use strict";

Expand Down Expand Up @@ -1281,73 +1281,20 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
value: function toArray(data) {
var frozen = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;

var key = this.key,
fn = void 0,
result = void 0;
var result = void 0;

if (data) {
fn = function () {
if (key) {
return function (a, b) {
var obj = clone(b[1]);

if (obj[key] === undefined) {
obj[key] = clone(b[0]);
}

if (frozen) {
Object.freeze(obj);
}

a.push(obj);

return a;
};
} else {
return function (a, b) {
var obj = clone(b[1]);

if (frozen) {
Object.freeze(obj);
}

a.push(obj);

return a;
};
}
}();
result = data.reduce(fn, []);
result = data.map(function (i) {
return frozen ? i[1] : clone(i[1]);
});
} else {
fn = function () {
if (key) {
return function (val, id) {
var obj = clone(val);

if (obj[key] === undefined) {
obj[key] = clone(id);
}

if (frozen) {
Object.freeze(obj);
}

result.push(obj);
};
} else {
return function (val) {
var obj = clone(val);
result = this.limit(0, this.total, true);

if (frozen) {
Object.freeze(obj);
}

result.push(obj);
};
}
}();
result = [];
this.forEach(fn);
if (frozen) {
result.forEach(function (i) {
Object.freeze(i);
});
}
}

return frozen ? Object.freeze(result) : result;
Expand Down Expand Up @@ -1465,7 +1412,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
}

factory.transform = cast;
factory.version = "3.0.1";
factory.version = "3.0.2";

// Node, AMD & window supported
if (typeof exports !== "undefined") {
Expand Down
Loading

0 comments on commit 37eaac5

Please sign in to comment.