Skip to content

Commit

Permalink
More
Browse files Browse the repository at this point in the history
  • Loading branch information
dumbmatter committed May 6, 2023
1 parent 2259e2e commit 7372599
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 11 deletions.
4 changes: 2 additions & 2 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@
}, 6000);

function checkModern() {
// Chrome 93, Firefox 92, Safari 15.4
if (Object.hasOwn === undefined) {
// Chrome 97, Firefox 104, Safari 15.4
if (Array.prototype.findLast === undefined) {
return false;
}

Expand Down
16 changes: 16 additions & 0 deletions src/common/polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,22 @@ if (!Array.prototype.at) {
}
}

// Chrome 97, Firefox 104, Safari 15.4
if (!Array.prototype.findLast) {
Object.defineProperty(Array.prototype, "findLast", {
value: function (cb: any) {
for (let i = this.length - 1; i >= 0; i--) {
if (cb(this[i])) {
return this[i];
}
}
},
configurable: true,
enumerable: false,
writable: true,
});
}

// Chrome 93, Firefox 92, Safari 15.4
if (!Object.hasOwn) {
Object.defineProperty(Object, "hasOwn", {
Expand Down
3 changes: 1 addition & 2 deletions src/ui/components/Dropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import findLast from "lodash-es/findLast";
import { useEffect, useState } from "react";
import type { CSSProperties } from "react";
import useDropdownOptions, {
Expand All @@ -14,7 +13,7 @@ export const getResponsiveValue = (
windowWidth: number,
) => {
if (Array.isArray(val)) {
return findLast(val, row => windowWidth >= row.minWidth)!.text;
return val.findLast(row => windowWidth >= row.minWidth)!.text;
}

return val;
Expand Down
4 changes: 1 addition & 3 deletions src/worker/core/realRosters/formatPlayerFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import nerfDraftProspect from "./nerfDraftProspect";
import oldAbbrevTo2020BBGMAbbrev from "./oldAbbrevTo2020BBGMAbbrev";
import setDraftProspectRatingsBasedOnDraftPosition from "./setDraftProspectRatingsBasedOnDraftPosition";
import { getEWA } from "../../util/advStats.basketball";
import findLast from "lodash-es/findLast";

const MINUTES_PER_GAME = 48;

Expand Down Expand Up @@ -410,8 +409,7 @@ const formatPlayerFactory = async (

let retiredYear;
if (ratings.retiredUntil !== undefined) {
const lastNonRetiredSeason = findLast(
allRatings,
const lastNonRetiredSeason = allRatings.findLast(
row => row.season < ratings.season && row.retiredUntil === undefined,
);
console.log("lastNonRetiredSeason", lastNonRetiredSeason);
Expand Down
3 changes: 2 additions & 1 deletion src/worker/views/negotiationList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ const updateNegotiationList = async () => {

const userTid = g.get("userTid");

let negotiations = await idb.cache.negotiations.getAll(); // For Multi Team Mode, might have other team's negotiations going on
let negotiations = await idb.cache.negotiations.getAll();

// For Multi Team Mode, might have other team's negotiations going on
negotiations = negotiations.filter(
negotiation => negotiation.tid === userTid,
);
Expand Down
4 changes: 1 addition & 3 deletions src/worker/views/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import type {
ViewInput,
} from "../../common/types";
import orderBy from "lodash-es/orderBy";
import findLast from "lodash-es/findLast";

const fixRatingsStatsAbbrevs = async (p: {
ratings?: {
Expand Down Expand Up @@ -428,8 +427,7 @@ export const getCommon = async (pid?: number, season?: number) => {
p.experience = Math.max(0, p.experience + offset2);

// Jersey number
const stats = findLast(
p.stats,
const stats = p.stats.findLast(
row => row.season === season && !row.playoffs,
);
if (stats) {
Expand Down

0 comments on commit 7372599

Please sign in to comment.