Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
refactor: remove usage of clone deep
  • Loading branch information
brunozoric committed Apr 13, 2026
commit 36c957c4a83503d063ebf89d4c129bd547a965c3
4 changes: 1 addition & 3 deletions packages/api-aco/src/utils/ListCache.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import cloneDeep from "lodash/cloneDeep.js";

export type Constructor<T> = new (...args: any[]) => T;

export interface IListCachePredicate<T> {
Expand Down Expand Up @@ -34,7 +32,7 @@ export class ListCache<T> implements IListCache<T> {
}

getItems(): T[] {
return cloneDeep(this.state);
return structuredClone(this.state);
}

addItems(items: T[]): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import cloneDeep from "lodash/cloneDeep.js";

export type Constructor<T> = new (...args: any[]) => T;

export interface IListCachePredicate<T> {
Expand Down Expand Up @@ -34,7 +32,7 @@ export class ListCache<T> implements IListCache<T> {
}

getItems(): T[] {
return cloneDeep(this.state);
return structuredClone(this.state);
}

addItems(items: T[]): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import cloneDeep from "lodash/cloneDeep.js";
import { makeAutoObservable, runInAction } from "mobx";
import { makeAutoObservable, observable, runInAction, toJS } from "mobx";
import { mdbid } from "@webiny/utils";

import type { FilterDTO } from "../domain/index.js";
import { FilterMapper, Loading, Sorter } from "../domain/index.js";
import type { FiltersGatewayInterface } from "../gateways/index.js";
Expand All @@ -10,19 +8,20 @@ export class FilterRepository {
private gateway: FiltersGatewayInterface;
private sorter: Sorter<FilterDTO>;
private loading: Loading;
private filters: FilterDTO[] = [];
private filters;
public readonly namespace: string;

constructor(gateway: FiltersGatewayInterface, namespace: string) {
this.gateway = gateway;
this.loading = new Loading();
this.namespace = namespace;
this.filters = observable.array<FilterDTO>([]);
this.sorter = new Sorter(["createdOn_DESC"]);
makeAutoObservable(this);
}

getFilters() {
return cloneDeep(this.filters);
return structuredClone(toJS(this.filters));
}

getLoading() {
Expand Down Expand Up @@ -58,15 +57,23 @@ export class FilterRepository {
}

runInAction(() => {
this.filters = this.sorter.sort(response.map(filter => FilterMapper.toDTO(filter)));
this.filters.replace(
this.sorter.sort(
response.map(filter => {
return FilterMapper.toDTO(filter);
})
)
);
});
}

async getFilterById(id: string) {
const filterInCache = this.filters.find(filter => filter.id === id);
const filterInCache = this.filters.find(filter => {
return filter.id === id;
});

if (filterInCache) {
return cloneDeep(filterInCache);
return structuredClone(toJS(filterInCache));
}

const response = await this.runWithLoading<FilterDTO>(this.gateway.get(id));
Expand All @@ -77,10 +84,10 @@ export class FilterRepository {

const filterDTO = FilterMapper.toDTO(response);
runInAction(() => {
this.filters = this.sorter.sort([filterDTO, ...this.filters]);
this.filters.replace(this.sorter.sort([filterDTO, ...toJS(this.filters)]));
});

return cloneDeep(filterDTO);
return structuredClone(toJS(filterDTO));
}

async createFilter(filter: FilterDTO) {
Expand All @@ -99,10 +106,10 @@ export class FilterRepository {

const filterDTO = FilterMapper.toDTO(response);
runInAction(() => {
this.filters = this.sorter.sort([filterDTO, ...this.filters]);
this.filters.replace(this.sorter.sort([filterDTO, ...toJS(this.filters)]));
});

return cloneDeep(filterDTO);
return structuredClone(toJS(filterDTO));
}

async updateFilter(filter: FilterDTO) {
Expand All @@ -122,14 +129,17 @@ export class FilterRepository {
const filterDTO = FilterMapper.toDTO(response);

runInAction(() => {
this.filters = this.sorter.sort([
...this.filters.slice(0, filterIndex),
{
...this.filters[filterIndex],
...filterDTO
},
...this.filters.slice(filterIndex + 1)
]);
const filters = toJS(this.filters);
this.filters.replace(
this.sorter.sort([
...filters.slice(0, filterIndex),
{
...filters[filterIndex],
...filterDTO
},
...filters.slice(filterIndex + 1)
])
);
});
}
}
Expand All @@ -149,7 +159,9 @@ export class FilterRepository {

if (response) {
runInAction(() => {
this.filters = this.sorter.sort(this.filters.filter(filter => filter.id !== id));
this.filters.replace(
this.sorter.sort(toJS(this.filters.filter(filter => filter.id !== id)))
);
});
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import cloneDeep from "lodash/cloneDeep.js";
import { makeAutoObservable, runInAction } from "mobx";

import { makeAutoObservable, runInAction, toJS } from "mobx";
import { Loading } from "./Loading.js";
import type { IconPackProviderInterface as IconPackProvider, IconType } from "./config/index.js";
import type { Icon } from "./types.js";
Expand Down Expand Up @@ -39,7 +37,7 @@ export class IconRepository {
}

getIcons() {
return cloneDeep(this.icons);
return structuredClone(toJS(this.icons));
}

addIcon(icon: Icon) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useMemo, useState } from "react";
import cloneDeep from "lodash/cloneDeep.js";
import type { FormOnSubmit } from "@webiny/form";
import { Form } from "@webiny/form";
import { i18n } from "@webiny/app/i18n/index.js";
Expand All @@ -14,7 +13,7 @@ import { EditFieldDrawerContainer } from "./EditFieldDrawerContainer.js";
const t = i18n.namespace("app-headless-cms/admin/components/editor");

function setupState(field: CmsModelField, contentModel: CmsEditorContentModel): EditFieldState {
const clonedField = cloneDeep(field);
const clonedField = structuredClone(field);

if (!clonedField.renderer || !clonedField.renderer.name) {
const [renderPlugin] = useRendererPlugins();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { Fragment } from "react";
import { css } from "@emotion/css";
import cloneDeep from "lodash/cloneDeep.js";
import debounce from "lodash/debounce.js";
import { plugins } from "@webiny/plugins";
import { Switch } from "@webiny/ui/Switch/index.js";
Expand Down Expand Up @@ -68,10 +67,10 @@ const onEnabledChange = (params: OnEnabledChangeParams): void => {
};

const onFormChange = debounce(({ data, validationValue, onChangeValidation, validatorIndex }) => {
const newValidationValue = cloneDeep(validationValue);
const newValidationValue = structuredClone(validationValue);
newValidationValue[validatorIndex] = {
...newValidationValue[validatorIndex],
...cloneDeep(data)
...structuredClone(data)
};
onChangeValidation(newValidationValue);
}, 200);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from "react";
import cloneDeep from "lodash/cloneDeep.js";
import { ReactComponent as DeleteIcon } from "@webiny/icons/delete_outline.svg";
import { ReactComponent as CloneIcon } from "@webiny/icons/library_add.svg";
import { ReactComponent as ArrowUpIcon } from "@webiny/icons/expand_less.svg";
Expand Down Expand Up @@ -210,7 +209,7 @@ export const MultiValueDynamicZone = (props: MultiValueDynamicZoneProps) => {
};

const cloneValue = (value: TemplateValue, index: number) => {
bind.appendValue(cloneDeep(value), index + 1);
bind.appendValue(structuredClone(value), index + 1);
};

const values: TemplateValue[] = bind.value || [];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { makeAutoObservable, runInAction } from "mobx";
import { makeAutoObservable, runInAction, toJS } from "mobx";
import {
ListQueryParamsRepository as Abstraction,
type BaseListParams,
Expand Down Expand Up @@ -75,7 +75,7 @@ export class ListQueryParamsRepositoryImpl<TParams extends BaseListParams>
}

private clone(value: TParams): TParams {
return structuredClone ? structuredClone(value) : JSON.parse(JSON.stringify(value));
return structuredClone(toJS(value));
}
}

Expand Down
3 changes: 1 addition & 2 deletions packages/pulumi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
"dependencies": {
"@pulumi/pulumi": "^3.230.0",
"@webiny/project": "0.0.0",
"find-up": "^8.0.0",
"lodash": "^4.18.1"
"find-up": "^8.0.0"
},
"devDependencies": {
"@types/lodash": "^4.17.24",
Expand Down
3 changes: 1 addition & 2 deletions packages/pulumi/src/createPulumiApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import type {
ResourceHandler
} from "~/types.js";
import type { PulumiAppRemoteResource } from "~/PulumiAppRemoteResource.js";
import cloneDeep from "lodash/cloneDeep.js";
import { DEFAULT_PROD_ENV_NAMES } from "./constants.js";

export function createPulumiApp<TResources extends Record<string, unknown>>(
Expand Down Expand Up @@ -256,7 +255,7 @@ function createPulumiAppResourceConfigProxy<T extends object>(obj: T) {
return new Proxy(obj, {
get(target, p: string) {
if (p === "clone") {
return () => cloneDeep(obj);
return () => structuredClone(obj);
}

type V = T[keyof T];
Expand Down
1 change: 0 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15026,7 +15026,6 @@ __metadata:
"@webiny/build-tools": "npm:0.0.0"
"@webiny/project": "npm:0.0.0"
find-up: "npm:^8.0.0"
lodash: "npm:^4.18.1"
rimraf: "npm:^6.1.3"
typescript: "npm:5.9.3"
languageName: unknown
Expand Down