Skip to content

Commit 0292735

Browse files
committed
fix: 修复错误修改DefaultOptions问题
1 parent 391d3cf commit 0292735

File tree

6 files changed

+24
-16
lines changed

6 files changed

+24
-16
lines changed

packages/s2-core/__tests__/unit/utils/merge.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ describe('merge test', () => {
1919
});
2020
});
2121

22+
test('should return new object', () => {
23+
const obj = { name: 'name' };
24+
const result = customMerge(obj, { age: 100 });
25+
26+
expect(obj).toEqual({ name: 'name' });
27+
expect(result).toEqual({ name: 'name', age: 100 });
28+
});
29+
2230
test('should get safety data config', () => {
2331
expect(getSafetyDataConfig(null)).toStrictEqual({
2432
data: [],

packages/s2-core/src/sheet-type/spread-sheet.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
isEmpty,
1010
isFunction,
1111
isString,
12-
merge,
1312
once,
1413
} from 'lodash';
1514
import { hideColumnsByThunkGroup } from '@/utils/hide-columns';
@@ -366,15 +365,18 @@ export abstract class SpreadSheet extends EE {
366365
*/
367366
public setThemeCfg(themeCfg: ThemeCfg) {
368367
const theme = themeCfg?.theme || {};
369-
this.theme = merge({}, getTheme({ ...themeCfg, spreadsheet: this }), theme);
368+
this.theme = customMerge(
369+
getTheme({ ...themeCfg, spreadsheet: this }),
370+
theme,
371+
);
370372
}
371373

372374
/**
373375
* Update pagination config which store in {@see options}
374376
* @param pagination
375377
*/
376378
public updatePagination(pagination: Pagination) {
377-
this.options = merge({}, this.options, {
379+
this.options = customMerge(this.options, {
378380
pagination,
379381
});
380382

@@ -406,7 +408,7 @@ export abstract class SpreadSheet extends EE {
406408
return;
407409
}
408410

409-
this.options = merge({}, this.options, { width, height });
411+
this.options = customMerge(this.options, { width, height });
410412
// resize the canvas
411413
this.container.changeSize(width, height);
412414
}
@@ -446,8 +448,7 @@ export abstract class SpreadSheet extends EE {
446448
*/
447449
public updateScrollOffset(offsetConfig: OffsetConfig): void {
448450
this.facet.updateScrollOffset(
449-
merge(
450-
{},
451+
customMerge(
451452
{
452453
offsetX: {
453454
value: undefined,

packages/s2-core/src/utils/merge.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isArray, isEmpty, merge, mergeWith } from 'lodash';
1+
import { isArray, isEmpty, mergeWith } from 'lodash';
22
import { DEFAULT_OPTIONS } from '../common/constant/options';
33
import { S2DataConfig, S2Options } from '@/common/interface';
44
import { DEFAULT_DATA_CONFIG } from '@/common/constant/dataConfig';
@@ -11,11 +11,11 @@ export const customMerge = (...objects: unknown[]) => {
1111
};
1212
const args = [...objects, customize] as [unknown, unknown];
1313

14-
return mergeWith(...args);
14+
return mergeWith({}, ...args);
1515
};
1616

1717
export const getSafetyDataConfig = (dataConfig: Partial<S2DataConfig>) => {
18-
const result = merge({}, DEFAULT_DATA_CONFIG, dataConfig) as S2DataConfig;
18+
const result = customMerge(DEFAULT_DATA_CONFIG, dataConfig) as S2DataConfig;
1919

2020
// 自定义树和数值为空的场景, 关闭 数值置于列头
2121
if (
@@ -28,4 +28,4 @@ export const getSafetyDataConfig = (dataConfig: Partial<S2DataConfig>) => {
2828
};
2929

3030
export const getSafetyOptions = (options: Partial<S2Options>) =>
31-
merge({}, DEFAULT_OPTIONS, options);
31+
customMerge(DEFAULT_OPTIONS, options);

packages/s2-core/src/utils/text.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import {
66
isNumber,
77
isString,
88
memoize,
9-
merge,
109
toString,
1110
values,
1211
} from 'lodash';
12+
import { customMerge } from '@/utils/merge';
1313
import { CellCfg, MultiData } from '@/common/interface';
1414
import { S2Options } from '@/common/interface/s2Options';
1515
import { DefaultCellTheme } from '@/common/interface/theme';
@@ -302,7 +302,7 @@ const getStyle = (
302302
: derivedMeasureText?.mainDown || dataCellTheme.icon.downIconColor;
303303
if (isDerivedMeasure) {
304304
const isUp = getDataState(value);
305-
return merge(style, {
305+
return customMerge(style, {
306306
fill: isUp ? upFill : downFill,
307307
});
308308
}

packages/s2-core/src/utils/tooltip.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import {
2222
mapKeys,
2323
every,
2424
isObject,
25-
merge,
2625
} from 'lodash';
2726
import * as CSS from 'csstype';
2827
import { Event as CanvasEvent } from '@antv/g-canvas';

packages/s2-react/src/hooks/usePaginationEffect.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
2-
import { isEmpty, merge } from 'lodash';
2+
import { isEmpty } from 'lodash';
33
import type { SpreadSheet, S2Options } from '@antv/s2';
4-
import { getSafetyOptions } from '@antv/s2';
4+
import { getSafetyOptions, customMerge } from '@antv/s2';
55

66
export const usePaginationEffect = (
77
s2: SpreadSheet,
@@ -13,7 +13,7 @@ export const usePaginationEffect = (
1313
if (!s2 || isEmpty(options?.pagination)) {
1414
return;
1515
}
16-
const newOptions = merge({}, options, {
16+
const newOptions = customMerge(options, {
1717
pagination: {
1818
current,
1919
pageSize,

0 commit comments

Comments
 (0)