Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup filterBy & mapBy prototype extensions #2602

Merged
merged 3 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions app/components/object-inspector/sort-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ export default class SortProperties extends Component {
@computed('args.properties')
get isArray() {
const props = A(this.args.properties || []);
return props.findBy('name', 'length') && props.findBy('name', '0');
return (
props.find((x) => x.name === 'length') &&
props.find((x) => x.name === '0')
);
}

/**
Expand All @@ -21,7 +24,7 @@ export default class SortProperties extends Component {
// limit arrays
let props = A(this.sorted);
if (this.isArray) {
const item = props.findBy('name', 'length');
const item = props.find((x) => x.name === 'length');
props.removeObject(item);
props.splice(0, 0, item);
}
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export default class ApplicationController extends Controller {
@action
droppedObject(objectId) {
let mixinStack = this.mixinStack;
let obj = mixinStack.findBy('objectId', objectId);
let obj = mixinStack.find((x) => x.objectId === objectId);
if (obj) {
let index = mixinStack.indexOf(obj);
let objectsToRemove = [];
Expand Down
10 changes: 5 additions & 5 deletions app/libs/resizable-columns.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export default class {
if (saved.columnVisibility && !isNone(saved.columnVisibility[id])) {
return saved.columnVisibility[id];
}
return this.columnSchema.findBy('id', id).visible;
return this.columnSchema.find((x) => x.id === id).visible;
}

/**
Expand Down Expand Up @@ -221,8 +221,8 @@ export default class {
let diff = this.tableWidth - totalWidth;
while (diff > 0) {
columns
.filter((col) => col.visible)
.sortBy('width')
.filter((x) => !!x.visible)
patricklx marked this conversation as resolved.
Show resolved Hide resolved
.sort((a, b) => a.width - b.width)
.forEach((column) => {
if (diff > 0) {
column.width++;
Expand All @@ -245,7 +245,7 @@ export default class {
* @param {Number} width The column's new width
*/
updateColumnWidth(id, width) {
let column = this._columns.findBy('id', id);
let column = this._columns.find((x) => x.id === id);
let previousWidth = column.width;
column.width = width;
let last = this._columns[this._columns.length - 1];
Expand All @@ -265,7 +265,7 @@ export default class {
* @param {String} id
*/
toggleVisibility(id) {
let column = this._columnVisibility.findBy('id', id);
let column = this._columnVisibility.find((x) => x.id === id);
column.visible = !column.visible;
if (!this._columnVisibility.isAny('visible')) {
// If this column was the last visible column
Expand Down
8 changes: 3 additions & 5 deletions app/models/promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ export default class Promise extends EmberObject {
@not('isSettled')
isPending;

get children() {
return [];
}
children = [];

@computed('isPending', '[email protected]')
get pendingBranch() {
Expand All @@ -76,7 +74,7 @@ export default class Promise extends EmberObject {
return true;
}
for (let i = 0; i < this.get('children.length'); i++) {
if (this.children.objectAt(i).get(cp)) {
if (this.children.at(i).get(cp)) {
return true;
}
}
Expand Down Expand Up @@ -204,7 +202,7 @@ export default class Promise extends EmberObject {
_allChildren() {
let children = [...this.children];
children.forEach((item) => {
children = [...children, item._allChildren()];
children = [...children, ...item._allChildren()];
});
return children;
}
Expand Down
4 changes: 2 additions & 2 deletions app/routes/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ export default class ApplicationRoute extends Route {

updateProperty(options) {
if (this.get('controller.mixinDetails.mixins')) {
const detail = this.get('controller.mixinDetails.mixins').objectAt(
const detail = this.get('controller.mixinDetails.mixins').at(
options.mixinIndex,
);
let property = detail.properties.findBy('name', options.property);
let property = detail.properties.find((x) => x.name === options.property);
if (!property) return;
set(property, 'value', options.value);
if (options.dependentKeys) {
Expand Down
2 changes: 1 addition & 1 deletion app/routes/deprecations.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default class DeprecationsRoute extends TabRoute {
let { deprecations } = this.controller;

message.deprecations.forEach((item) => {
let record = deprecations.findBy('id', item.id);
let record = deprecations.find((x) => x.id === item.id);
if (record) {
setProperties(record, item);
} else {
Expand Down
5 changes: 2 additions & 3 deletions app/routes/model-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ export default class ModelTypeRoute extends Route {

model(params) {
return new Promise((resolve) => {
const type = this.modelFor('model-types').findBy(
'name',
decodeURIComponent(params.type_id),
const type = this.modelFor('model-types').find(
(x) => x.name === decodeURIComponent(params.type_id),
);
if (type) {
resolve(type);
Expand Down
5 changes: 2 additions & 3 deletions app/routes/model-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ export default class ModelTypesRoute extends TabRoute {
updateModelTypes(message) {
let route = this;
message.modelTypes.forEach(function (modelType) {
const currentType = route.currentModel.findBy(
'objectId',
modelType.objectId,
const currentType = route.currentModel.find(
(x) => x.objectId === modelType.objectId,
);
set(currentType, 'count', modelType.count);
});
Expand Down
4 changes: 3 additions & 1 deletion app/routes/records.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ export default class RecordsRoute extends TabRoute {

updateRecords(message) {
message.records.forEach((record) => {
let currentRecord = this.currentModel.findBy('objectId', record.objectId);
let currentRecord = this.currentModel.find(
(x) => x.objectId === record.objectId,
);
if (currentRecord) {
set(currentRecord, 'columnValues', record.columnValues);
set(currentRecord, 'filterValues', record.filterValues);
Expand Down
2 changes: 1 addition & 1 deletion ember_debug/object-inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,7 @@ function calculateCP(object, item, errorsForObject) {
delete errorsForObject[property];
try {
if (object instanceof ArrayProxy && property == parseInt(property)) {
return object.objectAt(property);
return object.at(property);
}
return item.isGetter || property.includes?.('.')
? object[property]
Expand Down
6 changes: 3 additions & 3 deletions tests/ember_debug/container-debug-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ module('Ember Debug - Container', function (hooks) {

assert.strictEqual(name, 'container:types');
let types = emberA(message.types);
assert.ok(types.findBy('name', 'controller'));
assert.ok(types.findBy('name', 'route'));
assert.ok(types.find((x) => x.name === 'controller'));
assert.ok(types.find((x) => x.name === 'route'));
});

skip('#getInstances', async function t(assert) {
Expand All @@ -49,7 +49,7 @@ module('Ember Debug - Container', function (hooks) {

assert.strictEqual(name, 'container:instances');
let instances = emberA(message.instances);
assert.ok(instances.findBy('name', 'simple'));
assert.ok(instances.find((x) => x.name === 'simple'));
});

skip('#getInstances on a non existing type', async function t(assert) {
Expand Down
8 changes: 4 additions & 4 deletions tests/ember_debug/promise-debug-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ module('Ember Debug - Promise Debug', function (hooks) {

let promises = emberA(message.promises);

promise1 = promises.findBy('label', 'Promise1');
child1 = promises.findBy('label', 'Child1');
promise2 = promises.findBy('label', 'Promise2');
promise1 = promises.find((x) => x.label === 'Promise1');
child1 = promises.find((x) => x.label === 'Child1');
promise2 = promises.find((x) => x.label === 'Promise2');

assert.strictEqual(promise1.label, 'Promise1');
assert.strictEqual(promise1.state, 'fulfilled');
Expand Down Expand Up @@ -86,7 +86,7 @@ module('Ember Debug - Promise Debug', function (hooks) {
later(function () {
assert.strictEqual(name, 'promise:promisesUpdated');
let promises = emberA(message.promises);
let promise = promises.findBy('label', 'Promise1');
let promise = promises.find((x) => x.label === 'Promise1');
assert.ok(!!promise);
if (promise) {
assert.strictEqual(promise.label, 'Promise1');
Expand Down
Loading