Skip to content

Commit 4fe0424

Browse files
authored
cleanup filterBy & mapBy prototype extensions (#2602)
1 parent e41b9dc commit 4fe0424

File tree

12 files changed

+32
-31
lines changed

12 files changed

+32
-31
lines changed

app/components/object-inspector/sort-properties.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ export default class SortProperties extends Component {
77
@computed('args.properties')
88
get isArray() {
99
const props = A(this.args.properties || []);
10-
return props.findBy('name', 'length') && props.findBy('name', '0');
10+
return (
11+
props.find((x) => x.name === 'length') &&
12+
props.find((x) => x.name === '0')
13+
);
1114
}
1215

1316
/**
@@ -21,7 +24,7 @@ export default class SortProperties extends Component {
2124
// limit arrays
2225
let props = A(this.sorted);
2326
if (this.isArray) {
24-
const item = props.findBy('name', 'length');
27+
const item = props.find((x) => x.name === 'length');
2528
props.removeObject(item);
2629
props.splice(0, 0, item);
2730
}

app/controllers/application.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ export default class ApplicationController extends Controller {
173173
@action
174174
droppedObject(objectId) {
175175
let mixinStack = this.mixinStack;
176-
let obj = mixinStack.findBy('objectId', objectId);
176+
let obj = mixinStack.find((x) => x.objectId === objectId);
177177
if (obj) {
178178
let index = mixinStack.indexOf(obj);
179179
let objectsToRemove = [];

app/libs/resizable-columns.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export default class {
165165
if (saved.columnVisibility && !isNone(saved.columnVisibility[id])) {
166166
return saved.columnVisibility[id];
167167
}
168-
return this.columnSchema.findBy('id', id).visible;
168+
return this.columnSchema.find((x) => x.id === id).visible;
169169
}
170170

171171
/**
@@ -221,8 +221,8 @@ export default class {
221221
let diff = this.tableWidth - totalWidth;
222222
while (diff > 0) {
223223
columns
224-
.filter((col) => col.visible)
225-
.sortBy('width')
224+
.filter((col) => !!col.visible)
225+
.sort((a, b) => a.width - b.width)
226226
.forEach((column) => {
227227
if (diff > 0) {
228228
column.width++;
@@ -245,7 +245,7 @@ export default class {
245245
* @param {Number} width The column's new width
246246
*/
247247
updateColumnWidth(id, width) {
248-
let column = this._columns.findBy('id', id);
248+
let column = this._columns.find((x) => x.id === id);
249249
let previousWidth = column.width;
250250
column.width = width;
251251
let last = this._columns[this._columns.length - 1];
@@ -265,7 +265,7 @@ export default class {
265265
* @param {String} id
266266
*/
267267
toggleVisibility(id) {
268-
let column = this._columnVisibility.findBy('id', id);
268+
let column = this._columnVisibility.find((x) => x.id === id);
269269
column.visible = !column.visible;
270270
if (!this._columnVisibility.isAny('visible')) {
271271
// If this column was the last visible column

app/models/promise.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ export default class Promise extends EmberObject {
5252
@not('isSettled')
5353
isPending;
5454

55-
get children() {
56-
return [];
57-
}
55+
children = [];
5856

5957
@computed('isPending', '[email protected]')
6058
get pendingBranch() {
@@ -76,7 +74,7 @@ export default class Promise extends EmberObject {
7674
return true;
7775
}
7876
for (let i = 0; i < this.get('children.length'); i++) {
79-
if (this.children.objectAt(i).get(cp)) {
77+
if (this.children.at(i).get(cp)) {
8078
return true;
8179
}
8280
}
@@ -204,7 +202,7 @@ export default class Promise extends EmberObject {
204202
_allChildren() {
205203
let children = [...this.children];
206204
children.forEach((item) => {
207-
children = [...children, item._allChildren()];
205+
children = [...children, ...item._allChildren()];
208206
});
209207
return children;
210208
}

app/routes/application.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ export default class ApplicationRoute extends Route {
7676

7777
updateProperty(options) {
7878
if (this.get('controller.mixinDetails.mixins')) {
79-
const detail = this.get('controller.mixinDetails.mixins').objectAt(
79+
const detail = this.get('controller.mixinDetails.mixins').at(
8080
options.mixinIndex,
8181
);
82-
let property = detail.properties.findBy('name', options.property);
82+
let property = detail.properties.find((x) => x.name === options.property);
8383
if (!property) return;
8484
set(property, 'value', options.value);
8585
if (options.dependentKeys) {

app/routes/deprecations.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default class DeprecationsRoute extends TabRoute {
4141
let { deprecations } = this.controller;
4242

4343
message.deprecations.forEach((item) => {
44-
let record = deprecations.findBy('id', item.id);
44+
let record = deprecations.find((x) => x.id === item.id);
4545
if (record) {
4646
setProperties(record, item);
4747
} else {

app/routes/model-type.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ export default class ModelTypeRoute extends Route {
77

88
model(params) {
99
return new Promise((resolve) => {
10-
const type = this.modelFor('model-types').findBy(
11-
'name',
12-
decodeURIComponent(params.type_id),
10+
const type = this.modelFor('model-types').find(
11+
(x) => x.name === decodeURIComponent(params.type_id),
1312
);
1413
if (type) {
1514
resolve(type);

app/routes/model-types.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ export default class ModelTypesRoute extends TabRoute {
3737
updateModelTypes(message) {
3838
let route = this;
3939
message.modelTypes.forEach(function (modelType) {
40-
const currentType = route.currentModel.findBy(
41-
'objectId',
42-
modelType.objectId,
40+
const currentType = route.currentModel.find(
41+
(x) => x.objectId === modelType.objectId,
4342
);
4443
set(currentType, 'count', modelType.count);
4544
});

app/routes/records.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ export default class RecordsRoute extends TabRoute {
4343

4444
updateRecords(message) {
4545
message.records.forEach((record) => {
46-
let currentRecord = this.currentModel.findBy('objectId', record.objectId);
46+
let currentRecord = this.currentModel.find(
47+
(x) => x.objectId === record.objectId,
48+
);
4749
if (currentRecord) {
4850
set(currentRecord, 'columnValues', record.columnValues);
4951
set(currentRecord, 'filterValues', record.filterValues);

ember_debug/object-inspector.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,7 @@ function calculateCP(object, item, errorsForObject) {
13041304
delete errorsForObject[property];
13051305
try {
13061306
if (object instanceof ArrayProxy && property == parseInt(property)) {
1307-
return object.objectAt(property);
1307+
return object.at(property);
13081308
}
13091309
return item.isGetter || property.includes?.('.')
13101310
? object[property]

0 commit comments

Comments
 (0)