History

Sanity-check decaffeinate app.Collection

Simon Legner committed 2 years ago

Commit 6f5beac1 parent c022a291 file · +8 −21Browse files

Unified · Split

assets/javascripts/collections/collection.js+8−21
@@ -1,12 +1,3 @@
1−// TODO: This file was created by bulk-decaffeinate.
2−// Sanity-check the conversion and remove this comment.
3−/*
4− * decaffeinate suggestions:
5− * DS101: Remove unnecessary use of Array.from
6− * DS102: Remove unnecessary code created because of implicit returns
7− * DS207: Consider shorter variations of null checks
8− * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
9− */
101 app.Collection = class Collection {
112 constructor(objects) {
123 if (objects == null) {
@@ -24,7 +15,7 @@ app.Collection = class Collection { · 11 unmodified lines
2415 objects = [];
2516 }
2617 this.models = [];
27− for (var object of Array.from(objects)) {
18+ for (var object of objects) {
2819 this.add(object);
2920 }
3021 }
@@ -33,11 +24,11 @@ app.Collection = class Collection { · 2 unmodified lines
3324 if (object instanceof app.Model) {
3425 this.models.push(object);
3526 } else if (object instanceof Array) {
36− for (var obj of Array.from(object)) {
27+ for (var obj of object) {
3728 this.add(obj);
3829 }
3930 } else if (object instanceof app.Collection) {
40− this.models.push(...Array.from(object.all() || []));
31+ this.models.push(...(object.all() || []));
4132 } else {
4233 this.models.push(new (this.model())(object));
4334 }
@@ -56,7 +47,7 @@ app.Collection = class Collection { · 12 unmodified lines
5647 }
5748
5849 each(fn) {
59− for (var model of Array.from(this.models)) {
50+ for (var model of this.models) {
6051 fn(model);
6152 }
6253 }
@@ -66,24 +57,20 @@ app.Collection = class Collection { · 3 unmodified lines
6657 }
6758
6859 contains(model) {
69− return this.models.indexOf(model) >= 0;
60+ return this.models.includes(model);
7061 }
7162
7263 findBy(attr, value) {
73− for (var model of Array.from(this.models)) {
74− if (model[attr] === value) {
75− return model;
76− }
77− }
64+ return this.models.find((model) => model[attr] === value);
7865 }
7966
8067 findAllBy(attr, value) {
81− return Array.from(this.models).filter((model) => model[attr] === value);
68+ return this.models.filter((model) => model[attr] === value);
8269 }
8370
8471 countAllBy(attr, value) {
8572 let i = 0;
86− for (var model of Array.from(this.models)) {
73+ for (var model of this.models) {
8774 if (model[attr] === value) {
8875 i += 1;
8976 }