just-clone -> window.structuredClone + remove other unused deps

This commit is contained in:
Kalle 2025-03-13 21:49:04 +02:00
parent 0faac11560
commit adad157015
12 changed files with 22 additions and 63 deletions

View File

@ -11,7 +11,6 @@ import {
} from "@remix-run/node";
import { Form, useLoaderData } from "@remix-run/react";
import Compressor from "compressorjs";
import clone from "just-clone";
import { nanoid } from "nanoid";
import * as React from "react";
import { useTranslation } from "react-i18next";
@ -474,7 +473,7 @@ function LinkedUsers() {
<UserSearch
inputName="user"
onChange={(newUser) => {
const newUsers = clone(users);
const newUsers = structuredClone(users);
newUsers[i] = { ...newUsers[i], userId: newUser.id };
setUsers(newUsers);

View File

@ -4,7 +4,6 @@ import {
useLoaderData,
useSearchParams,
} from "@remix-run/react";
import clone from "just-clone";
import { nanoid } from "nanoid";
import * as React from "react";
import { useTranslation } from "react-i18next";
@ -240,7 +239,7 @@ export default function WeaponsBuildsPage() {
};
const handleFilterChange = (i: number, newFilter: Partial<BuildFilter>) => {
const newFilters = clone(filters);
const newFilters = structuredClone(filters);
newFilters[i] = {
...(filters[i] as AbilityBuildFilter),

View File

@ -1,4 +1,3 @@
import clone from "just-clone";
import type { MapPoolMap } from "~/db/types";
import {
type ModeShort,
@ -108,8 +107,8 @@ export class MapPool {
return this.stageModePairs.length;
}
getClonedObject(): MapPoolObject {
return clone(this.parsed) as MapPoolObject;
getClonedObject() {
return structuredClone(this.parsed) as MapPoolObject;
}
toString() {

View File

@ -1,4 +1,3 @@
import clone from "just-clone";
import type { Tables } from "~/db/tables";
import type { Group } from "~/db/types";
import { TIERS } from "~/features/mmr/mmr-constants";
@ -524,7 +523,7 @@ export function tierDifferenceToRangeOrExact({
tier: TieredSkill["tier"] | [TieredSkill["tier"], TieredSkill["tier"]];
} {
if (ourTier.name === theirTier.name && ourTier.isPlus === theirTier.isPlus) {
return { diff: 0, tier: clone(ourTier) };
return { diff: 0, tier: structuredClone(ourTier) };
}
const tiers = hasLeviathan
@ -546,11 +545,14 @@ export function tierDifferenceToRangeOrExact({
const upperBound = tier1Idx + idxDiff;
if (lowerBound < 0 || upperBound >= tiers.length) {
return { diff: idxDiff, tier: clone(theirTier) };
return { diff: idxDiff, tier: structuredClone(theirTier) };
}
const lowerTier = tiers[lowerBound];
const upperTier = tiers[upperBound];
return { diff: idxDiff, tier: [clone(lowerTier), clone(upperTier)] };
return {
diff: idxDiff,
tier: [structuredClone(lowerTier), structuredClone(upperTier)],
};
}

View File

@ -1,6 +1,5 @@
import { Link, useFetcher, useLoaderData } from "@remix-run/react";
import clsx from "clsx";
import clone from "just-clone";
import * as React from "react";
import { Avatar } from "~/components/Avatar";
import { Button } from "~/components/Button";
@ -140,7 +139,7 @@ function _TeamRoster({
const didCancel = !editing;
if (didCancel) {
setCheckedPlayers?.((oldPlayers) => {
const newPlayers = clone(oldPlayers);
const newPlayers = structuredClone(oldPlayers);
newPlayers[idx] = activeRoster ?? [];
return newPlayers;
});
@ -157,7 +156,7 @@ function _TeamRoster({
const onPointsChange = React.useCallback(
(newPoint: number) => {
setPoints((points) => {
const newPoints = clone(points);
const newPoints = structuredClone(points);
newPoints[idx] = newPoint;
return newPoints;
});
@ -218,7 +217,7 @@ function _TeamRoster({
if (!setCheckedPlayers) return;
setCheckedPlayers((oldPlayers) => {
const newPlayers = clone(oldPlayers);
const newPlayers = structuredClone(oldPlayers);
if (oldPlayers[idx].includes(playerId)) {
newPlayers[idx] = newPlayers[idx].filter((id) => id !== playerId);
} else {

View File

@ -1,6 +1,5 @@
/** Map list generation logic for "TO pick" as in the map list is defined beforehand by TO and teams don't pick */
import clone from "just-clone";
import shuffle from "just-shuffle";
import type { Tables, TournamentRoundMaps } from "~/db/tables";
import type { Round } from "~/modules/brackets-model";
@ -199,7 +198,7 @@ function modesWithSZBiased({
}
if (flavor === "SZ_FIRST" && modes.includes("SZ")) {
const result: ModeShort[] = clone(modes);
const result: ModeShort[] = structuredClone(modes);
const szIndex = result.indexOf("SZ");
result.splice(szIndex, 1);
result.unshift("SZ");

View File

@ -17,7 +17,6 @@ import type { ActionFunction, LoaderFunctionArgs } from "@remix-run/node";
import { redirect } from "@remix-run/node";
import { Link, useFetcher, useNavigation } from "@remix-run/react";
import clsx from "clsx";
import clone from "just-clone";
import * as React from "react";
import { Alert } from "~/components/Alert";
import { Button } from "~/components/Button";
@ -161,7 +160,7 @@ export default function TournamentSeedsPage() {
type="button"
onClick={() => {
setTeamOrder(
clone(tournament.ctx.teams)
structuredClone(tournament.ctx.teams)
.sort(
(a, b) =>
(b.avgSeedingSkillOrdinal ?? Number.NEGATIVE_INFINITY) -

View File

@ -4,7 +4,6 @@ import {
useMatches,
useSearchParams,
} from "@remix-run/react";
import clone from "just-clone";
import * as React from "react";
import { useTranslation } from "react-i18next";
import { AbilitiesSelector } from "~/components/AbilitiesSelector";
@ -319,7 +318,7 @@ function GearSelector({
// let's not overwrite current selections
if (!currentAbilities.every((a) => a === "UNKNOWN")) return;
const newAbilities = clone(abilities);
const newAbilities = structuredClone(abilities);
newAbilities[gearIndex] = abilitiesFromExistingGear;
setAbilities(newAbilities);

View File

@ -1,4 +1,3 @@
import clone from "just-clone";
import type {
CrudInterface,
Database,
@ -130,16 +129,18 @@ export class InMemoryDatabase implements CrudInterface {
try {
if (arg === undefined) {
// @ts-expect-error imported
return this.data[table].map(clone);
return this.data[table].map((val) => structuredClone(val));
}
if (typeof arg === "number") {
// @ts-expect-error imported
return clone(this.data[table].find((d) => d?.id === arg));
return structuredClone(this.data[table].find((d) => d?.id === arg));
}
// @ts-expect-error imported
return this.data[table].filter(this.makeFilter(arg)).map(clone);
return this.data[table]
.filter(this.makeFilter(arg))
.map((val) => structuredClone(val));
} catch (error) {
return null;
}

View File

@ -1,7 +1,6 @@
// TODO: when more examples of permissions profile difference between
// this implementation and one that takes arrays
import clone from "just-clone";
import shuffle from "just-shuffle";
import invariant from "~/utils/invariant";
@ -89,7 +88,7 @@ export function nullFilledArray(size: number): null[] {
export function pickRandomItem<T>(array: T[]): T {
invariant(array.length > 0, "Can't pick from empty array");
const shuffled = shuffle(clone(array));
const shuffled = shuffle(structuredClone(array));
return shuffled[0];
}

32
package-lock.json generated
View File

@ -33,9 +33,7 @@
"i18next-browser-languagedetector": "^8.0.4",
"i18next-http-backend": "^2.6.2",
"isbot": "^5.1.23",
"just-camel-case": "^6.2.0",
"just-capitalize": "^3.2.0",
"just-clone": "^6.2.0",
"just-compare": "^2.3.0",
"just-random-integer": "^4.2.0",
"just-shuffle": "^4.2.0",
@ -55,7 +53,6 @@
"react-flip-toolkit": "7.2.4",
"react-hook-form": "^7.54.2",
"react-i18next": "^15.4.1",
"react-responsive-masonry": "2.2.0",
"react-use": "^17.6.0",
"react-use-draggable-scroll": "^0.4.7",
"reconnecting-websocket": "^4.4.0",
@ -78,7 +75,6 @@
"@types/nprogress": "^0.2.3",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@types/react-responsive-masonry": "^2.1.3",
"@types/web-push": "^3.6.4",
"cross-env": "^7.0.3",
"ley": "^0.8.1",
@ -6732,16 +6728,6 @@
"@types/react": "^18.0.0"
}
},
"node_modules/@types/react-responsive-masonry": {
"version": "2.6.0",
"resolved": "https://registry.npmjs.org/@types/react-responsive-masonry/-/react-responsive-masonry-2.6.0.tgz",
"integrity": "sha512-MF2ql1CjzOoL9fLWp6L3ABoyzBUP/YV71wyb3Fx+cViYNj7+tq3gDCllZHbLg1LQfGOQOEGbV2P7TOcUeGiR6w==",
"dev": true,
"license": "MIT",
"dependencies": {
"@types/react": "*"
}
},
"node_modules/@types/scheduler": {
"version": "0.16.8",
"resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.8.tgz",
@ -10667,24 +10653,12 @@
"graceful-fs": "^4.1.6"
}
},
"node_modules/just-camel-case": {
"version": "6.2.0",
"resolved": "https://registry.npmjs.org/just-camel-case/-/just-camel-case-6.2.0.tgz",
"integrity": "sha512-ICenRLXwkQYLk3UyvLQZ+uKuwFVJ3JHFYFn7F2782G2Mv2hW8WPePqgdhpnjGaqkYtSVWnyCESZhGXUmY3/bEg==",
"license": "MIT"
},
"node_modules/just-capitalize": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/just-capitalize/-/just-capitalize-3.2.0.tgz",
"integrity": "sha512-FK8U9A5AHCIGxlEXg3RFJkb9Nz/fS9luJlrfRf0bFBZU6xnIQ6tbwl+HitMJLwCFszZqVaXQcyeoy8/PYABS6A==",
"license": "MIT"
},
"node_modules/just-clone": {
"version": "6.2.0",
"resolved": "https://registry.npmjs.org/just-clone/-/just-clone-6.2.0.tgz",
"integrity": "sha512-1IynUYEc/HAwxhi3WDpIpxJbZpMCvvrrmZVqvj9EhpvbH8lls7HhdhiByjL7DkAaWlLIzpC0Xc/VPvy/UxLNjA==",
"license": "MIT"
},
"node_modules/just-compare": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/just-compare/-/just-compare-2.3.0.tgz",
@ -13692,12 +13666,6 @@
}
}
},
"node_modules/react-responsive-masonry": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/react-responsive-masonry/-/react-responsive-masonry-2.2.0.tgz",
"integrity": "sha512-IYbnfe2tWCZ3pvyTLyBWPj7uv5ZmNOULYMcAZi5a47ZLhSotOck1vkkISq6gP2qiyWdMvPfeMhjvYzUYGw9BOQ==",
"license": "MIT"
},
"node_modules/react-router": {
"version": "6.30.0",
"resolved": "https://registry.npmjs.org/react-router/-/react-router-6.30.0.tgz",

View File

@ -49,9 +49,7 @@
"i18next-browser-languagedetector": "^8.0.4",
"i18next-http-backend": "^2.6.2",
"isbot": "^5.1.23",
"just-camel-case": "^6.2.0",
"just-capitalize": "^3.2.0",
"just-clone": "^6.2.0",
"just-compare": "^2.3.0",
"just-random-integer": "^4.2.0",
"just-shuffle": "^4.2.0",
@ -71,7 +69,6 @@
"react-flip-toolkit": "7.2.4",
"react-hook-form": "^7.54.2",
"react-i18next": "^15.4.1",
"react-responsive-masonry": "2.2.0",
"react-use": "^17.6.0",
"react-use-draggable-scroll": "^0.4.7",
"reconnecting-websocket": "^4.4.0",
@ -94,7 +91,6 @@
"@types/nprogress": "^0.2.3",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@types/react-responsive-masonry": "^2.1.3",
"@types/web-push": "^3.6.4",
"cross-env": "^7.0.3",
"ley": "^0.8.1",