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