|
|
|
@ -1,12 +1,3 @@
|
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
|
// Sanity-check the conversion and remove this comment.
|
|
|
|
|
/*
|
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
|
* DS101: Remove unnecessary use of Array.from
|
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
|
|
|
|
|
*/
|
|
|
|
|
app.Collection = class Collection {
|
|
|
|
|
constructor(objects) {
|
|
|
|
|
if (objects == null) {
|
|
|
|
@ -24,7 +15,7 @@ app.Collection = class Collection {
|
|
|
|
|
objects = [];
|
|
|
|
|
}
|
|
|
|
|
this.models = [];
|
|
|
|
|
for (var object of Array.from(objects)) {
|
|
|
|
|
for (var object of objects) {
|
|
|
|
|
this.add(object);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -33,11 +24,11 @@ app.Collection = class Collection {
|
|
|
|
|
if (object instanceof app.Model) {
|
|
|
|
|
this.models.push(object);
|
|
|
|
|
} else if (object instanceof Array) {
|
|
|
|
|
for (var obj of Array.from(object)) {
|
|
|
|
|
for (var obj of object) {
|
|
|
|
|
this.add(obj);
|
|
|
|
|
}
|
|
|
|
|
} else if (object instanceof app.Collection) {
|
|
|
|
|
this.models.push(...Array.from(object.all() || []));
|
|
|
|
|
this.models.push(...(object.all() || []));
|
|
|
|
|
} else {
|
|
|
|
|
this.models.push(new (this.model())(object));
|
|
|
|
|
}
|
|
|
|
@ -56,7 +47,7 @@ app.Collection = class Collection {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
each(fn) {
|
|
|
|
|
for (var model of Array.from(this.models)) {
|
|
|
|
|
for (var model of this.models) {
|
|
|
|
|
fn(model);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -66,24 +57,20 @@ app.Collection = class Collection {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
contains(model) {
|
|
|
|
|
return this.models.indexOf(model) >= 0;
|
|
|
|
|
return this.models.includes(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
findBy(attr, value) {
|
|
|
|
|
for (var model of Array.from(this.models)) {
|
|
|
|
|
if (model[attr] === value) {
|
|
|
|
|
return model;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return this.models.find((model) => model[attr] === value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
findAllBy(attr, value) {
|
|
|
|
|
return Array.from(this.models).filter((model) => model[attr] === value);
|
|
|
|
|
return this.models.filter((model) => model[attr] === value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
countAllBy(attr, value) {
|
|
|
|
|
let i = 0;
|
|
|
|
|
for (var model of Array.from(this.models)) {
|
|
|
|
|
for (var model of this.models) {
|
|
|
|
|
if (model[attr] === value) {
|
|
|
|
|
i += 1;
|
|
|
|
|
}
|
|
|
|
|