Sanity-check decaffeinate app.Collection

pull/1441/head
Simon Legner 1 year ago
parent c022a29fab
commit 6f5beacfc4

@ -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 { app.Collection = class Collection {
constructor(objects) { constructor(objects) {
if (objects == null) { if (objects == null) {
@ -24,7 +15,7 @@ app.Collection = class Collection {
objects = []; objects = [];
} }
this.models = []; this.models = [];
for (var object of Array.from(objects)) { for (var object of objects) {
this.add(object); this.add(object);
} }
} }
@ -33,11 +24,11 @@ app.Collection = class Collection {
if (object instanceof app.Model) { if (object instanceof app.Model) {
this.models.push(object); this.models.push(object);
} else if (object instanceof Array) { } else if (object instanceof Array) {
for (var obj of Array.from(object)) { for (var obj of object) {
this.add(obj); this.add(obj);
} }
} else if (object instanceof app.Collection) { } else if (object instanceof app.Collection) {
this.models.push(...Array.from(object.all() || [])); this.models.push(...(object.all() || []));
} else { } else {
this.models.push(new (this.model())(object)); this.models.push(new (this.model())(object));
} }
@ -56,7 +47,7 @@ app.Collection = class Collection {
} }
each(fn) { each(fn) {
for (var model of Array.from(this.models)) { for (var model of this.models) {
fn(model); fn(model);
} }
} }
@ -66,24 +57,20 @@ app.Collection = class Collection {
} }
contains(model) { contains(model) {
return this.models.indexOf(model) >= 0; return this.models.includes(model);
} }
findBy(attr, value) { findBy(attr, value) {
for (var model of Array.from(this.models)) { return this.models.find((model) => model[attr] === value);
if (model[attr] === value) {
return model;
}
}
} }
findAllBy(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) { countAllBy(attr, value) {
let i = 0; let i = 0;
for (var model of Array.from(this.models)) { for (var model of this.models) {
if (model[attr] === value) { if (model[attr] === value) {
i += 1; i += 1;
} }

Loading…
Cancel
Save