replace immer with mutative

This commit is contained in:
Nate Kelley 2025-02-07 14:11:05 -07:00
parent d02874f5fd
commit 9054d61cf7
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
4 changed files with 21 additions and 22 deletions

21
web/package-lock.json generated
View File

@ -53,7 +53,6 @@
"font-color-contrast": "^11.1.0",
"framer-motion": "^12.0.6",
"html2canvas": "^1.4.1",
"immer": "^10.1.1",
"js-cookie": "^3.0.5",
"jspdf": "^2.5.2",
"jspdf-autotable": "^3.8.4",
@ -62,6 +61,7 @@
"monaco-sql-languages": "^0.12.2",
"monaco-themes": "^0.4.4",
"monaco-yaml": "^5.2.3",
"mutative": "^1.1.0",
"next": "14.2.22",
"next-themes": "^0.4.4",
"next-transpile-modules": "^10.0.1",
@ -10031,16 +10031,6 @@
"node": ">= 4"
}
},
"node_modules/immer": {
"version": "10.1.1",
"resolved": "https://registry.npmjs.org/immer/-/immer-10.1.1.tgz",
"integrity": "sha512-s2MPrmjovJcoMaHtx6K11Ra7oD05NT97w1IC5zpMkT6Atjr7H8LjaDd81iIxUYpMKSRRNMJE703M1Fhr/TctHw==",
"license": "MIT",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/immer"
}
},
"node_modules/immutable": {
"version": "5.0.3",
"resolved": "https://registry.npmjs.org/immutable/-/immutable-5.0.3.tgz",
@ -13698,6 +13688,15 @@
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
},
"node_modules/mutative": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/mutative/-/mutative-1.1.0.tgz",
"integrity": "sha512-2PJADREjOusk3iJkD3rXV2YjAxTuaLxdfqtqTEt6vcY07LtEBR1seHuBHXWEIuscqRDGvbauYPs+A4Rj/KTczQ==",
"license": "MIT",
"engines": {
"node": ">=14.0"
}
},
"node_modules/mz": {
"version": "2.7.0",
"resolved": "https://registry.npmjs.org/mz/-/mz-2.7.0.tgz",

View File

@ -60,7 +60,6 @@
"font-color-contrast": "^11.1.0",
"framer-motion": "^12.0.6",
"html2canvas": "^1.4.1",
"immer": "^10.1.1",
"js-cookie": "^3.0.5",
"jspdf": "^2.5.2",
"jspdf-autotable": "^3.8.4",
@ -69,6 +68,7 @@
"monaco-sql-languages": "^0.12.2",
"monaco-themes": "^0.4.4",
"monaco-yaml": "^5.2.3",
"mutative": "^1.1.0",
"next": "14.2.22",
"next-themes": "^0.4.4",
"next-transpile-modules": "^10.0.1",

View File

@ -2,7 +2,7 @@ import { FileType } from '@/api/asset_interfaces';
import { useMemo, useState } from 'react';
import { FileConfig, FileView, FileViewConfig, FileViewSecondary } from './interfaces';
import { useMemoizedFn } from 'ahooks';
import { produce } from 'immer';
import { create } from 'mutative';
export const useChatFileLayout = ({
selectedFileId,
@ -71,7 +71,7 @@ export const useChatFileLayout = ({
const closeSecondaryView = useMemoizedFn(() => {
if (!selectedFileId || !selectedFileViewConfig || !selectedFileView) return;
setFileViews(
produce((draft) => {
create((draft) => {
if (!draft[selectedFileId]?.fileViewConfig?.[selectedFileView]) return;
draft[selectedFileId].fileViewConfig[selectedFileView].secondaryView = null;
})

View File

@ -6,7 +6,7 @@ import {
DEFAULT_CHART_CONFIG_ENTRIES
} from '@/api/asset_interfaces';
import type { BusterChartConfigProps } from '@/components/charts';
import { produce } from 'immer';
import { create } from 'mutative';
import isEmpty from 'lodash/isEmpty';
import { createDefaultColumnLabelFormats } from './createDefaultColumnFormats';
import { createDefaultColumnSettings } from './createDefaultColumnSettings';
@ -124,21 +124,21 @@ export const createDefaultChartConfig = (
const dataMetadata = message.data_metadata;
const pieChartAxis = chartConfig?.pieChartAxis;
const newChartConfig = produce(DEFAULT_CHART_CONFIG, (draft) => {
DEFAULT_CHART_CONFIG_ENTRIES.forEach(([key, defaultValue]) => {
const _key = key as keyof IBusterMetricChartConfig;
const chartConfigValue = chartConfig?.[_key];
const newChartConfig = create(DEFAULT_CHART_CONFIG, (draft) => {
DEFAULT_CHART_CONFIG_ENTRIES.forEach(([_key, defaultValue]) => {
const key = _key as keyof IBusterMetricChartConfig;
const chartConfigValue = chartConfig?.[key];
const handler = keySpecificHandlers[_key];
const handler = keySpecificHandlers[key];
if (!handler) {
(draft as any)[_key] = chartConfigValue ?? defaultValue;
(draft as any)[key] = chartConfigValue ?? defaultValue;
return;
}
const result = handler(chartConfigValue, dataMetadata, pieChartAxis);
(draft as any)[_key] = result ?? defaultValue;
(draft as any)[key] = result ?? defaultValue;
});
});