Skip to content

Commit

Permalink
do not rely on Array prototype extensions (#692)
Browse files Browse the repository at this point in the history
* Array.any() relies on prototype extensions

* remove remaining usage of array prototype extensions
  • Loading branch information
jelhan authored Oct 18, 2023
1 parent 9d019bb commit 3a23719
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 35 deletions.
2 changes: 1 addition & 1 deletion app/components/bs-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class BsForm extends BaseBsForm {
async validate(model) {
const isInvalid = Object.getOwnPropertyNames(
Object.getPrototypeOf(model),
).any((potentialValidationKey) => {
).some((potentialValidationKey) => {
// Validation getters must be named `propertyValidation` by our convention
if (!potentialValidationKey.endsWith('Validation')) {
return false;
Expand Down
12 changes: 8 additions & 4 deletions app/components/create-options-dates.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ export default class CreateOptionsDates extends Component {
// Options may contain the same date multiple times with different ime
// Must filter out those duplicates as otherwise unselect would only
// remove one entry but not all duplicates.
return this.args.options
.map(({ value }) => DateTime.fromISO(value).toISODate())
.uniq()
.map((isoDate) => DateTime.fromISO(isoDate));
return Array.from(
// using Set to remove duplicate values
new Set(
this.args.options.map(({ value }) =>
DateTime.fromISO(value).toISODate(),
),
),
).map((isoDate) => DateTime.fromISO(isoDate));
}

get calendarCenterNext() {
Expand Down
2 changes: 1 addition & 1 deletion app/components/create-options-datetime.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class FormDataOption {
const optionsForThisDay = formData.optionsGroupedByDay[day];
const isDuplicate = optionsForThisDay
.slice(0, optionsForThisDay.indexOf(this))
.any((option) => option.time == this.time);
.some((option) => option.time == this.time);
if (isDuplicate) {
return new IntlMessage('create.options-datetime.error.duplicatedDate');
}
Expand Down
2 changes: 1 addition & 1 deletion app/components/create-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class FormData {
return new IntlMessage('create.options.error.notEnoughDates');
}

if (options.any((option) => !option.isValid)) {
if (options.some((option) => !option.isValid)) {
return new IntlMessage('create.options.error.invalidOption');
}

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/create/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default class CreateSettings extends Controller {
// set timezone if there is atleast one option with time
if (
poll.isFindADate &&
poll.options.any((option) => {
poll.options.toArray().some((option) => {
return option.hasTime;
})
) {
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/poll-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ export default class PollErrorController extends Controller {
}

get notFound() {
return this.model.errors.firstObject.status === '404';
return this.model.errors[0].status === '404';
}
}
33 changes: 13 additions & 20 deletions app/instance-initializers/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,27 @@ export default {
};

function getLocale(availableLocales) {
let methods = [getSavedLocale, getLocaleByBrowser];
let locale;

methods.any((method) => {
let preferredLocales = method();
let match;
for (const method of [getSavedLocale, getLocaleByBrowser]) {
const preferredLocales = method();

if (isEmpty(preferredLocales)) {
return false;
continue;
}

match = preferredLocales.find((preferredLocale) => {
return availableLocales.indexOf(preferredLocale) !== -1;
});
const supportedPreferredLocale = preferredLocales.find(
(preferredLocale) => {
return availableLocales.indexOf(preferredLocale) !== -1;
},
);

if (isEmpty(match)) {
return false;
if (isEmpty(supportedPreferredLocale)) {
continue;
}

locale = match;
return true;
});

if (locale) {
return locale;
} else {
return 'en';
return supportedPreferredLocale;
}

return 'en';
}

function getLocaleByBrowser() {
Expand Down
2 changes: 1 addition & 1 deletion app/models/poll.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default class Poll extends Model {
return false;
}

return this.options.any((option) => {
return this.options.toArray().some((option) => {
let dayStringLength = 10; // 'YYYY-MM-DD'.length
return option.title.length > dayStringLength;
});
Expand Down
1 change: 0 additions & 1 deletion app/templates/create/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<BsForm
@formLayout="horizontal"
@model={{@model.formData}}
@onInvalid={{(scroll-first-invalid-element-into-view-port)}}
@onSubmit={{this.submit}}
as |form|
>
Expand Down
2 changes: 1 addition & 1 deletion config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = function (environment) {
locationType: 'hash',
EmberENV: {
EXTEND_PROTOTYPES: {
Array: true,
Array: false,
Date: false,
String: false,
Function: true,
Expand Down
4 changes: 1 addition & 3 deletions tests/acceptance/participate-in-a-poll-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ module('Acceptance | participate in a poll', function (hooks) {
assert.equal(currentRouteName(), 'poll.participation');
assert.equal(find('.name input').value, '', 'input for name is cleared');
assert.notOk(
findAll('input[type="radio"]')
.toArray()
.some((el) => el.checked),
findAll('input[type="radio"]').some((el) => el.checked),
'radios are cleared',
);

Expand Down

0 comments on commit 3a23719

Please sign in to comment.