Skip to content

Commit 0399cd7

Browse files
authored
refactor: Fallow - break import cycle to reduce change cascade risk (#2596)
* refactor: Fallow - break import cycle to reduce change cascade risk
1 parent 32f4a0c commit 0399cd7

6 files changed

Lines changed: 36 additions & 31 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"fallow": "fallow",
5252
"fallow:dead-code": "fallow dead-code --production",
5353
"fallow:dupes": "fallow dupes",
54-
"fallow:health": "fallow health",
54+
"fallow:health": "fallow health --coverage test/vitest-coverage",
5555
"fallow:fix:preview": "fallow fix --dry-run --production",
5656
"fallow:fix": "fallow fix --production",
5757
"lint": "oxlint .",

packages/common/src/extensions/slickCellExcelCopyManager.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { BindingEventService } from '@slickgrid-universal/binding';
22
import { isPrimitiveOrHTML, stripTags } from '@slickgrid-universal/utils';
3-
import { SlickEventHandler, SlickGlobalEditorLock, type SlickDataView, type SlickGrid } from '../core/index.js';
3+
import { SlickEventHandler, SlickGlobalEditorLock } from '../core/slickCore.js';
4+
import type { SlickDataView } from '../core/slickDataview.js';
5+
import type { SlickGrid } from '../core/slickGrid.js';
46
import type {
57
Column,
68
EditCommand,
@@ -10,7 +12,8 @@ import type {
1012
FormatterResultWithText,
1113
GridOption,
1214
} from '../interfaces/index.js';
13-
import { SlickCellExternalCopyManager, SlickHybridSelectionModel } from './index.js';
15+
import { SlickCellExternalCopyManager } from './slickCellExternalCopyManager.js';
16+
import { SlickHybridSelectionModel } from './slickHybridSelectionModel.js';
1417

1518
/*
1619
This manager enables users to copy/paste data from/to an external Spreadsheet application

packages/common/src/extensions/slickGroupItemMetadataProvider.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
import { createDomElement, extend, isHtml } from '@slickgrid-universal/utils';
2-
import {
3-
applyHtmlToElement,
4-
SlickEventHandler,
5-
SlickGroup,
6-
type SlickDataView,
7-
type SlickEventData,
8-
type SlickGrid,
9-
} from '../core/index.js';
2+
import { SlickEventHandler, SlickGroup, type SlickEventData } from '../core/slickCore.js';
3+
import type { SlickDataView } from '../core/slickDataview.js';
4+
import type { SlickGrid } from '../core/slickGrid.js';
5+
import { applyHtmlToElement } from '../core/utils.js';
106
import type {
117
Column,
128
GridOption,

packages/common/src/filter-conditions/dateFilterCondition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { dayStart } from '@formkit/tempo';
22
import { type FieldType, type SearchTerm } from '../enums/index.js';
33
import type { FilterConditionOption } from '../interfaces/index.js';
4-
import { mapTempoDateFormatWithFieldType, tryParseDate } from '../services/index.js';
4+
import { mapTempoDateFormatWithFieldType, tryParseDate } from '../services/dateUtils.js';
55
import { testFilterCondition } from './filterUtilities.js';
66

77
/**

packages/common/src/sortComparers/__tests__/sortUtilities.spec.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,58 @@
11
import { describe, expect, it, vi } from 'vitest';
22
import { SortDirectionNumber } from '../../enums/index.js';
33
import type { Column } from '../../interfaces/index.js';
4-
import { SortComparers } from '../sortComparers.index.js';
4+
import * as booleanModule from '../booleanSortComparer.js';
5+
import * as numericModule from '../numericSortComparer.js';
6+
import * as objectStringModule from '../objectStringSortComparer.js';
57
import { sortByFieldType } from '../sortUtilities.js';
8+
import * as stringModule from '../stringSortComparer.js';
69

710
describe('sortUtilities', () => {
8-
it('should call the SortComparers.boolean when FieldType is boolean', () => {
9-
const spy = vi.spyOn(SortComparers, 'boolean');
11+
it('should call the booleanSortComparer when FieldType is boolean', () => {
12+
const spy = vi.spyOn(booleanModule, 'booleanSortComparer');
1013
sortByFieldType('boolean', 0, 4, SortDirectionNumber.asc, { id: 'field1', field: 'field1' });
1114
expect(spy).toHaveBeenCalledWith(0, 4, SortDirectionNumber.asc, { id: 'field1', field: 'field1' }, undefined);
1215
});
1316

14-
it('should call the SortComparers.numeric when FieldType is number', () => {
15-
const spy = vi.spyOn(SortComparers, 'numeric');
17+
it('should call the numericSortComparer when FieldType is number', () => {
18+
const spy = vi.spyOn(numericModule, 'numericSortComparer');
1619
sortByFieldType('number', 0, 4, SortDirectionNumber.asc, { id: 'field1', field: 'field1' });
1720
expect(spy).toHaveBeenCalledWith(0, 4, SortDirectionNumber.asc, { id: 'field1', field: 'field1' }, undefined);
1821
});
1922

20-
it('should call the SortComparers.numeric when FieldType is integer', () => {
21-
const spy = vi.spyOn(SortComparers, 'numeric');
23+
it('should call the numericSortComparer when FieldType is integer', () => {
24+
const spy = vi.spyOn(numericModule, 'numericSortComparer');
2225
sortByFieldType('integer', 0, 4, SortDirectionNumber.asc, { id: 'field1', field: 'field1' });
2326
expect(spy).toHaveBeenCalledWith(0, 4, SortDirectionNumber.asc, { id: 'field1', field: 'field1' }, undefined);
2427
});
2528

26-
it('should call the SortComparers.numeric when FieldType is float', () => {
27-
const spy = vi.spyOn(SortComparers, 'numeric');
29+
it('should call the numericSortComparer when FieldType is float', () => {
30+
const spy = vi.spyOn(numericModule, 'numericSortComparer');
2831
sortByFieldType('float', 0, 4, SortDirectionNumber.asc, { id: 'field1', field: 'field1' });
2932
expect(spy).toHaveBeenCalledWith(0, 4, SortDirectionNumber.asc, { id: 'field1', field: 'field1' }, undefined);
3033
});
3134

32-
it('should call the SortComparers.string when FieldType is a string (which is also the default)', () => {
35+
it('should call the stringSortComparer when FieldType is a string (which is also the default)', () => {
3336
const string1 = 'John';
3437
const string2 = 'Jane';
35-
const spy = vi.spyOn(SortComparers, 'string');
38+
const spy = vi.spyOn(stringModule, 'stringSortComparer');
3639
sortByFieldType('string', string1, string2, SortDirectionNumber.asc, { id: 'field1', field: 'field1' });
3740
expect(spy).toHaveBeenCalledWith(string1, string2, SortDirectionNumber.asc, { id: 'field1', field: 'field1' }, undefined);
3841
});
3942

40-
it('should call the SortComparers.date when FieldType is any date types', () => {
43+
it('should call the date comparer when FieldType is any date types', () => {
4144
const result1 = sortByFieldType('dateIso', '2020-01-01', '2020-02-01', SortDirectionNumber.asc, { id: 'field1', field: 'field1' });
4245
expect(result1).toBeLessThan(0);
4346

4447
const result2 = sortByFieldType('dateIso', '2020-02-01', '2020-01-01', SortDirectionNumber.asc, { id: 'field1', field: 'field1' });
4548
expect(result2).toBeGreaterThan(0);
4649
});
4750

48-
it('should call the SortComparers.objectString when FieldType is objectString', () => {
51+
it('should call the objectStringSortComparer when FieldType is objectString', () => {
4952
const object1 = { firstName: 'John', lastName: 'Z' };
5053
const object2 = { firstName: 'Jane', lastName: 'Doe' };
5154
const mockColumn = { id: 'field1', field: 'field1', dataKey: 'firstName' } as Column;
52-
const spy = vi.spyOn(SortComparers, 'objectString');
55+
const spy = vi.spyOn(objectStringModule, 'objectStringSortComparer');
5356
sortByFieldType('object', object1, object2, SortDirectionNumber.asc, mockColumn);
5457
expect(spy).toHaveBeenCalledWith(object1, object2, SortDirectionNumber.asc, mockColumn, undefined);
5558
});

packages/common/src/sortComparers/sortUtilities.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { type FieldType, type SortDirectionNumber } from '../enums/index.js';
22
import type { Column, GridOption } from '../interfaces/index.js';
33
import { isColumnDateType } from '../services/utilities.js';
4+
import { booleanSortComparer } from './booleanSortComparer.js';
45
import { getAssociatedDateSortComparer } from './dateUtilities.js';
5-
import { SortComparers } from './index.js';
6+
import { numericSortComparer } from './numericSortComparer.js';
7+
import { objectStringSortComparer } from './objectStringSortComparer.js';
8+
import { stringSortComparer } from './stringSortComparer.js';
69

710
export function sortByFieldType(
811
fieldType: FieldType,
@@ -20,22 +23,22 @@ export function sortByFieldType(
2023
} else {
2124
switch (fieldType) {
2225
case 'boolean':
23-
sortResult = SortComparers.boolean(value1, value2, sortDirection, sortColumn, gridOptions);
26+
sortResult = booleanSortComparer(value1, value2, sortDirection, sortColumn, gridOptions);
2427
break;
2528
case 'float':
2629
case 'integer':
2730
case 'number':
28-
sortResult = SortComparers.numeric(value1, value2, sortDirection, sortColumn, gridOptions);
31+
sortResult = numericSortComparer(value1, value2, sortDirection, sortColumn, gridOptions);
2932
break;
3033
case 'object':
31-
sortResult = SortComparers.objectString(value1, value2, sortDirection, sortColumn, gridOptions);
34+
sortResult = objectStringSortComparer(value1, value2, sortDirection, sortColumn, gridOptions);
3235
break;
3336
case 'string':
3437
case 'text':
3538
case 'password':
3639
case 'readonly':
3740
default:
38-
sortResult = SortComparers.string(value1, value2, sortDirection, sortColumn, gridOptions);
41+
sortResult = stringSortComparer(value1, value2, sortDirection, sortColumn, gridOptions);
3942
break;
4043
}
4144
}

0 commit comments

Comments
 (0)