Unified · Split
| @@ -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 | − */ | |
| 10 | 1 | app.Collection = class Collection { |
| 11 | 2 | constructor(objects) { |
| 12 | 3 | if (objects == null) { |
| @@ -24,7 +15,7 @@ app.Collection = class Collection { · 11 unmodified lines | ||
| 24 | 15 | objects = []; |
| 25 | 16 | } |
| 26 | 17 | this.models = []; |
| 27 | − for (var object of Array.from(objects)) { | |
| 18 | + for (var object of objects) { | |
| 28 | 19 | this.add(object); |
| 29 | 20 | } |
| 30 | 21 | } |
| @@ -33,11 +24,11 @@ app.Collection = class Collection { · 2 unmodified lines | ||
| 33 | 24 | if (object instanceof app.Model) { |
| 34 | 25 | this.models.push(object); |
| 35 | 26 | } else if (object instanceof Array) { |
| 36 | − for (var obj of Array.from(object)) { | |
| 27 | + for (var obj of object) { | |
| 37 | 28 | this.add(obj); |
| 38 | 29 | } |
| 39 | 30 | } else if (object instanceof app.Collection) { |
| 40 | − this.models.push(...Array.from(object.all() || [])); | |
| 31 | + this.models.push(...(object.all() || [])); | |
| 41 | 32 | } else { |
| 42 | 33 | this.models.push(new (this.model())(object)); |
| 43 | 34 | } |
| @@ -56,7 +47,7 @@ app.Collection = class Collection { · 12 unmodified lines | ||
| 56 | 47 | } |
| 57 | 48 | |
| 58 | 49 | each(fn) { |
| 59 | − for (var model of Array.from(this.models)) { | |
| 50 | + for (var model of this.models) { | |
| 60 | 51 | fn(model); |
| 61 | 52 | } |
| 62 | 53 | } |
| @@ -66,24 +57,20 @@ app.Collection = class Collection { · 3 unmodified lines | ||
| 66 | 57 | } |
| 67 | 58 | |
| 68 | 59 | contains(model) { |
| 69 | − return this.models.indexOf(model) >= 0; | |
| 60 | + return this.models.includes(model); | |
| 70 | 61 | } |
| 71 | 62 | |
| 72 | 63 | 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); | |
| 78 | 65 | } |
| 79 | 66 | |
| 80 | 67 | findAllBy(attr, value) { |
| 81 | − return Array.from(this.models).filter((model) => model[attr] === value); | |
| 68 | + return this.models.filter((model) => model[attr] === value); | |
| 82 | 69 | } |
| 83 | 70 | |
| 84 | 71 | countAllBy(attr, value) { |
| 85 | 72 | let i = 0; |
| 86 | − for (var model of Array.from(this.models)) { | |
| 73 | + for (var model of this.models) { | |
| 87 | 74 | if (model[attr] === value) { |
| 88 | 75 | i += 1; |
| 89 | 76 | } |