Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

fix(sheets-data-validation): break formula and list cache initialization cycle (#8076)

Univer637f27baaec0
diff --git a/packages/sheets-data-validation/src/services/__tests__/dv-formula.service.spec.ts b/packages/sheets-data-validation/src/services/__tests__/dv-formula.service.spec.ts
index 640100b828..b1b0e414ce 100644
--- a/packages/sheets-data-validation/src/services/__tests__/dv-formula.service.spec.ts
+++ b/packages/sheets-data-validation/src/services/__tests__/dv-formula.service.spec.ts
@@ -14,135 +14,96 @@
* limitations under the License.
*/
-import type { IUniverInstanceService } from '@univerjs/core';
-import type { DataValidationModel, DataValidatorRegistryService } from '@univerjs/data-validation';
-import type { RegisterOtherFormulaService } from '@univerjs/engine-formula';
-import type { DataValidationCacheService } from '../dv-cache.service';
-import type { DataValidationListCacheService } from '../dv-list-cache.service';
-import { DataValidationType, UniverInstanceType } from '@univerjs/core';
-import { OtherFormulaBizType } from '@univerjs/engine-formula';
-import { Subject } from 'rxjs';
-import { describe, expect, it, vi } from 'vitest';
+import type { ISheetDataValidationRule } from '@univerjs/core';
+import { DataValidationType, ICommandService, Univer, UniverInstanceType } from '@univerjs/core';
+import { DataValidationModel, DataValidatorRegistryService } from '@univerjs/data-validation';
+import {
+ ActiveDirtyManagerService,
+ IActiveDirtyManagerService,
+ OtherFormulaMarkDirty,
+ RegisterOtherFormulaService,
+ RemoveOtherFormulaMutation,
+ SetFormulaCalculationResultMutation,
+ SetOtherFormulaMutation,
+} from '@univerjs/engine-formula';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import { DataValidationCacheService } from '../dv-cache.service';
import { DataValidationFormulaService } from '../dv-formula.service';
+import { DataValidationListCacheService } from '../dv-list-cache.service';
-describe('DataValidationFormulaService', () => {
- it('registers formula rules, fetches results, removes them, and reacts to formula result changes', async () => {
- const formulaResult$ = new Subject<any>();
- const registerOtherFormulaService = {
- formulaResult$,
- registerFormulaWithRange: vi.fn((unitId: string, subUnitId: string, formula: string, _ranges, extra) => `${extra.ruleId}-${formula}`),
- deleteFormula: vi.fn(),
- getFormulaValue: vi.fn(async (_unitId: string, _subUnitId: string, id: string) => ({ id })),
- getFormulaValueSync: vi.fn((_unitId: string, _subUnitId: string, id: string) => ({ id })),
- } as unknown as RegisterOtherFormulaService;
- const cacheService = {
- markRangeDirty: vi.fn(),
- } as unknown as DataValidationCacheService;
- const listCacheService = {
- markRuleDirty: vi.fn(),
- } as unknown as DataValidationListCacheService;
- const rule = {
- uid: 'rule-1',
- type: DataValidationType.DECIMAL,
- formula1: '=A1',
- formula2: '=B1',
- ranges: [{ startRow: 0, endRow: 0, startColumn: 0, endColumn: 0 }],
- } as any;
- const dataValidationModel = {
- getRuleById: vi.fn(() => rule),
- } as unknown as DataValidationModel;
- const validatorRegistryService = {
- getValidatorItem: vi.fn(() => ({ offsetFormulaByRange: false })),
- } as unknown as DataValidatorRegistryService;
- const instanceService = {
- getUnitType: vi.fn(() => UniverInstanceType.UNIVER_SHEET),
- } as unknown as IUniverInstanceService;
+let univer: Univer;
+beforeEach(() => {
+ univer = new Univer();
+ const injector = univer.__getInjector();
+ injector.add([DataValidationModel]);
+ injector.add([DataValidatorRegistryService]);
+ injector.add([DataValidationCacheService]);
+ injector.add([IActiveDirtyManagerService, { useClass: ActiveDirtyManagerService }]);
+ injector.add([RegisterOtherFormulaService]);
+ injector.add([DataValidationFormulaService]);
+ injector.add([DataValidationListCacheService]);
+ const commands = injector.get(ICommandService);
+ for (const command of [SetOtherFormulaMutation, RemoveOtherFormulaMutation, OtherFormulaMarkDirty, SetFormulaCalculationResultMutation]) {
+ commands.registerCommand(command);
+ }
+ univer.createUnit(UniverInstanceType.UNIVER_SHEET, {
+ id: 'unit-1',
+ sheets: { 'sheet-1': { id: 'sheet-1', name: 'Sheet1', rowCount: 10, columnCount: 10 } },
+ sheetOrder: ['sheet-1'],
+ });
+});
+afterEach(() => univer.dispose());
- const service = new DataValidationFormulaService(
- instanceService,
- registerOtherFormulaService,
- cacheService,
- dataValidationModel,
- validatorRegistryService,
- listCacheService
- );
+const rule: ISheetDataValidationRule = {
+ uid: 'rule-1',
+ type: DataValidationType.LIST,
+ formula1: '=A1:A2',
+ formula2: '#f00,#0f0,#00f',
+ ranges: [{ startRow: 0, endRow: 0, startColumn: 2, endColumn: 2 }],
+};
+describe('DataValidationFormulaService', () => {
+ it('refreshes list caches before range subscribers consume recalculated results', async () => {
+ const injector = univer.__getInjector();
+ const service = injector.get(DataValidationFormulaService);
+ const lists = injector.get(DataValidationListCacheService);
+ injector.get(DataValidationModel).addRule('unit-1', 'sheet-1', rule, 'command');
service.addRule('unit-1', 'sheet-1', rule);
-
- expect(registerOtherFormulaService.registerFormulaWithRange).toHaveBeenCalledWith(
- 'unit-1',
- 'sheet-1',
- '=A1',
- [{ startColumn: 0, endColumn: 0, startRow: 0, endRow: 0 }],
- { ruleId: 'rule-1' },
- OtherFormulaBizType.DATA_VALIDATION,
- 'rule-1'
- );
- expect(service.getRuleFormulaInfo('unit-1', 'sheet-1', 'rule-1')).toEqual([
- { id: 'rule-1-=A1', text: '=A1' },
- { id: 'rule-1-=B1', text: '=B1' },
- ]);
-
- await expect(service.getRuleFormulaResult('unit-1', 'sheet-1', 'rule-1')).resolves.toEqual([
- { id: 'rule-1-=A1' },
- { id: 'rule-1-=B1' },
- ]);
- expect(service.getRuleFormulaResultSync('unit-1', 'sheet-1', 'rule-1')).toEqual([
- { id: 'rule-1-=A1' },
- { id: 'rule-1-=B1' },
- ]);
-
- formulaResult$.next({
- 'unit-1': {
- 'sheet-1': [
- { extra: { ruleId: 'rule-1' } },
- ],
- },
+ const formulaId = service.getRuleFormulaInfo('unit-1', 'sheet-1', rule.uid)![0]!.id;
+ const pending = service.getRuleFormulaResult('unit-1', 'sheet-1', rule.uid);
+ lists.computeAndCache('unit-1', 'sheet-1', rule, null);
+ const observed = vi.fn(() => lists.getOrCompute('unit-1', 'sheet-1', rule).list);
+ injector.get(DataValidationCacheService).dirtyRanges$.subscribe(observed);
+ await injector.get(ICommandService).executeCommand(SetFormulaCalculationResultMutation.id, {
+ unitOtherData: { 'unit-1': { 'sheet-1': { [formulaId]: { 0: { 0: [[{ v: 'A' }, { v: 'B' }]] } } } } },
});
-
- expect(listCacheService.markRuleDirty).toHaveBeenCalledWith('unit-1', 'sheet-1', 'rule-1');
- expect(cacheService.markRangeDirty).toHaveBeenCalledWith('unit-1', 'sheet-1', rule.ranges);
-
- service.removeRule('unit-1', 'sheet-1', 'rule-1');
- expect(registerOtherFormulaService.deleteFormula).toHaveBeenCalledWith('unit-1', 'sheet-1', ['rule-1-=A1', 'rule-1-=B1']);
+ expect(observed).toHaveReturnedWith(['A', 'B']);
+ expect((await pending)?.[0]?.extra?.ruleId).toBe(rule.uid);
+ expect(service.getRuleFormulaResultSync('unit-1', 'sheet-1', rule.uid)?.[0]?.extra?.ruleId).toBe(rule.uid);
+ await injector.get(ICommandService).executeCommand(SetFormulaCalculationResultMutation.id, {
+ unitOtherData: { 'unit-1': { 'sheet-1': { [formulaId]: { 0: { 0: [[{ v: 'Updated' }]] } } } } },
+ });
+ expect(lists.getOrCompute('unit-1', 'sheet-1', rule).list).toEqual(['Updated']);
+ service.removeRule('unit-1', 'sheet-1', rule.uid);
+ expect(injector.get(RegisterOtherFormulaService).getFormulaValueSync('unit-1', 'sheet-1', formulaId)).toBeUndefined();
});
- it('skips registration for non-formula rules, checkbox rules, and missing entries', async () => {
- const formulaResult$ = new Subject<any>();
- const registerOtherFormulaService = {
- formulaResult$,
- registerFormulaWithRange: vi.fn(),
- deleteFormula: vi.fn(),
- getFormulaValue: vi.fn(),
- getFormulaValueSync: vi.fn(),
- } as unknown as RegisterOtherFormulaService;
-
- const service = new DataValidationFormulaService(
- { getUnitType: vi.fn(() => UniverInstanceType.UNIVER_DOC) } as unknown as IUniverInstanceService,
- registerOtherFormulaService,
- { markRangeDirty: vi.fn() } as unknown as DataValidationCacheService,
- { getRuleById: vi.fn(() => null) } as unknown as DataValidationModel,
- { getValidatorItem: vi.fn(() => ({ offsetFormulaByRange: true })) } as unknown as DataValidatorRegistryService,
- { markRuleDirty: vi.fn() } as unknown as DataValidationListCacheService
- );
-
- service.addRule('unit-1', 'sheet-1', {
- uid: 'rule-2',
- type: DataValidationType.DECIMAL,
- formula1: '1',
- formula2: '2',
- } as any);
- service.addRule('unit-1', 'sheet-1', {
- uid: 'rule-3',
- type: DataValidationType.CHECKBOX,
- formula1: '=A1',
- formula2: '=B1',
- } as any);
-
- expect(registerOtherFormulaService.registerFormulaWithRange).not.toHaveBeenCalled();
+ it('skips non-formula and checkbox rules and safely handles missing registrations', async () => {
+ const service = univer.__getInjector().get(DataValidationFormulaService);
+ service.addRule('unit-1', 'sheet-1', { ...rule, formula1: 'A,B', formula2: '' });
+ expect(service.getRuleFormulaInfo('unit-1', 'sheet-1', rule.uid)).toBeUndefined();
+ service.addRule('unit-1', 'sheet-1', { ...rule, type: DataValidationType.CHECKBOX });
+ expect(service.getRuleFormulaInfo('unit-1', 'sheet-1', rule.uid)).toBeUndefined();
await expect(service.getRuleFormulaResult('unit-1', 'sheet-1', 'missing')).resolves.toBeNull();
expect(service.getRuleFormulaResultSync('unit-1', 'sheet-1', 'missing')).toBeUndefined();
service.removeRule('unit-1', 'sheet-1', 'missing');
- expect(registerOtherFormulaService.deleteFormula).not.toHaveBeenCalled();
+ });
+
+ it('completes formula change subscriptions on disposal', () => {
+ const service = univer.__getInjector().get(DataValidationFormulaService);
+ const complete = vi.fn();
+ service.ruleFormulaResultChanged$.subscribe({ complete });
+ service.dispose();
+ expect(complete).toHaveBeenCalledOnce();
});
});
diff --git a/packages/sheets-data-validation/src/services/__tests__/dv-list-cache.service.spec.ts b/packages/sheets-data-validation/src/services/__tests__/dv-list-cache.service.spec.ts
index d814896cd9..4e5b525a06 100644
--- a/packages/sheets-data-validation/src/services/__tests__/dv-list-cache.service.spec.ts
+++ b/packages/sheets-data-validation/src/services/__tests__/dv-list-cache.service.spec.ts
@@ -14,41 +14,70 @@
* limitations under the License.
*/
-import type { Injector } from '@univerjs/core';
-import type { DataValidationModel } from '@univerjs/data-validation';
-import { Subject } from 'rxjs';
-import { describe, expect, it, vi } from 'vitest';
+import type { ISheetDataValidationRule } from '@univerjs/core';
+import { DataValidationType, ICommandService, Univer, UniverInstanceType } from '@univerjs/core';
+import { DataValidationModel, DataValidatorRegistryService, UpdateRuleType } from '@univerjs/data-validation';
+import {
+ ActiveDirtyManagerService,
+ IActiveDirtyManagerService,
+ OtherFormulaMarkDirty,
+ RegisterOtherFormulaService,
+ RemoveOtherFormulaMutation,
+ SetFormulaCalculationResultMutation,
+ SetOtherFormulaMutation,
+} from '@univerjs/engine-formula';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import { DataValidationCacheService } from '../dv-cache.service';
import { DataValidationFormulaService } from '../dv-formula.service';
import { DataValidationListCacheService } from '../dv-list-cache.service';
-describe('DataValidationListCacheService', () => {
- it('computes, caches, invalidates, and clears list items', () => {
- const ruleChange$ = new Subject<any>();
- const formulaService = {
- getRuleFormulaResultSync: vi.fn(() => [
- { result: [[[[{ v: 'A' }, { v: 'B' }, { v: '#VALUE!' }, { v: 1, s: { n: { pattern: '0.00' } } }]]]] },
- ]),
- };
- const injector = {
- get(token: unknown) {
- if (token === DataValidationFormulaService) {
- return formulaService;
- }
-
- throw new Error(`Unknown token: ${String(token)}`);
- },
- } as unknown as Injector;
- const dataValidationModel = {
- ruleChange$,
- } as unknown as DataValidationModel;
+let univer: Univer;
+beforeEach(() => {
+ univer = new Univer();
+ const injector = univer.__getInjector();
+ injector.add([DataValidationModel]);
+ injector.add([DataValidatorRegistryService]);
+ injector.add([DataValidationCacheService]);
+ injector.add([IActiveDirtyManagerService, { useClass: ActiveDirtyManagerService }]);
+ injector.add([RegisterOtherFormulaService]);
+ injector.add([DataValidationFormulaService]);
+ injector.add([DataValidationListCacheService]);
+ const commands = injector.get(ICommandService);
+ for (const command of [SetOtherFormulaMutation, RemoveOtherFormulaMutation, OtherFormulaMarkDirty, SetFormulaCalculationResultMutation]) {
+ commands.registerCommand(command);
+ }
+ univer.createUnit(UniverInstanceType.UNIVER_SHEET, {
+ id: 'unit-1',
+ sheets: { 'sheet-1': { id: 'sheet-1', name: 'Sheet1', rowCount: 10, columnCount: 10 } },
+ sheetOrder: ['sheet-1'],
+ });
+});
+afterEach(() => univer.dispose());
- const service = new DataValidationListCacheService(injector, dataValidationModel);
- const rule = {
- uid: 'rule-1',
- formula1: '=A1',
- formula2: '#f00,#0f0,#00f',
- } as any;
+const rule: ISheetDataValidationRule = {
+ uid: 'rule-1',
+ type: DataValidationType.LIST,
+ formula1: '=A1:A2',
+ formula2: '#f00,#0f0,#00f',
+ ranges: [{ startRow: 0, endRow: 0, startColumn: 2, endColumn: 2 }],
+};
+describe('DataValidationListCacheService', () => {
+ it('computes and caches formatted formula lists and invalidates removed rules', async () => {
+ const injector = univer.__getInjector();
+ const service = injector.get(DataValidationListCacheService);
+ const formulas = injector.get(DataValidationFormulaService);
+ injector.get(DataValidationModel).addRule('unit-1', 'sheet-1', rule, 'command');
+ formulas.addRule('unit-1', 'sheet-1', rule);
+ const formulaId = formulas.getRuleFormulaInfo('unit-1', 'sheet-1', rule.uid)![0]!.id;
+ await injector.get(ICommandService).executeCommand(SetFormulaCalculationResultMutation.id, {
+ unitOtherData: { 'unit-1': { 'sheet-1': { [formulaId]: { 0: { 0: [[
+ { v: 'A' },
+ { v: 'B' },
+ { v: '#VALUE!' },
+ { v: 1, s: { n: { pattern: '0.00' } } },
+ ]] } } } } },
+ });
const first = service.getOrCompute('unit-1', 'sheet-1', rule);
expect(first.list).toEqual(['A', 'B', '1.00']);
expect(first.listWithColor).toEqual([
@@ -58,41 +87,34 @@ describe('DataValidationListCacheService', () => {
]);
expect(first.colorMap).toEqual({ A: '#f00', B: '#0f0', '1.00': '#00f' });
expect(first.set.has('A')).toBe(true);
-
expect(service.getOrCompute('unit-1', 'sheet-1', rule)).toBe(first);
- expect(formulaService.getRuleFormulaResultSync).toHaveBeenCalledTimes(1);
-
- service.markRuleDirty('unit-1', 'sheet-1', 'rule-1');
- expect(service.getCache('unit-1', 'sheet-1', 'rule-1')).toBeUndefined();
-
- service.setCache('unit-1', 'sheet-1', 'rule-2', first);
- expect(service.getCache('unit-1', 'sheet-1', 'rule-2')).toBe(first);
-
- ruleChange$.next({ type: 'remove', unitId: 'unit-1', subUnitId: 'sheet-1', rule: { uid: 'rule-2' } });
- expect(service.getCache('unit-1', 'sheet-1', 'rule-2')).toBeUndefined();
-
+ service.markRuleDirty('unit-1', 'sheet-1', rule.uid);
+ expect(service.getCache('unit-1', 'sheet-1', rule.uid)).toBeUndefined();
+ service.setCache('unit-1', 'sheet-1', rule.uid, first);
+ injector.get(DataValidationModel).removeRule('unit-1', 'sheet-1', rule.uid, 'command');
+ expect(service.getCache('unit-1', 'sheet-1', rule.uid)).toBeUndefined();
+ service.setCache('unit-1', 'sheet-1', rule.uid, first);
service.clear();
- expect(service.getCache('unit-1', 'sheet-1', 'rule-1')).toBeUndefined();
+ expect(service.getCache('unit-1', 'sheet-1', rule.uid)).toBeUndefined();
});
- it('supports non-formula lists and update invalidation', () => {
- const ruleChange$ = new Subject<any>();
- const service = new DataValidationListCacheService(
- {
- get() {
- return {
- getRuleFormulaResultSync: vi.fn(),
- };
- },
- } as unknown as Injector,
- { ruleChange$ } as unknown as DataValidationModel
- );
-
- const item = service.computeAndCache('unit-1', 'sheet-1', { uid: 'rule-3', formula1: 'x,y,,z', formula2: '' } as any, null);
+ it('supports literal lists and removes subscriptions on disposal', () => {
+ const injector = univer.__getInjector();
+ const service = injector.get(DataValidationListCacheService);
+ const item = service.computeAndCache('unit-1', 'sheet-1', { ...rule, formula1: 'x,y,,z', formula2: '' }, null);
expect(item.list).toEqual(['x', 'y', 'z']);
expect(item.colorMap).toEqual({});
-
- ruleChange$.next({ type: 'update', unitId: 'unit-1', subUnitId: 'sheet-1', rule: { uid: 'rule-3' } });
- expect(service.getCache('unit-1', 'sheet-1', 'rule-3')).toBeUndefined();
+ const model = injector.get(DataValidationModel);
+ model.addRule('unit-1', 'sheet-1', rule, 'command');
+ model.updateRule('unit-1', 'sheet-1', rule.uid, {
+ type: UpdateRuleType.SETTING,
+ payload: { type: DataValidationType.LIST, formula1: 'Updated' },
+ }, 'command');
+ expect(service.getCache('unit-1', 'sheet-1', rule.uid)).toBeUndefined();
+ const dirty = vi.spyOn(service, 'markRuleDirty');
+ service.dispose();
+ injector.get(DataValidationModel).addRule('unit-1', 'sheet-1', rule, 'command');
+ injector.get(DataValidationModel).removeRule('unit-1', 'sheet-1', rule.uid, 'command');
+ expect(dirty).not.toHaveBeenCalled();
});
});
diff --git a/packages/sheets-data-validation/src/services/dv-formula.service.ts b/packages/sheets-data-validation/src/services/dv-formula.service.ts
index 0be58f89ec..fc5ddd376e 100644
--- a/packages/sheets-data-validation/src/services/dv-formula.service.ts
+++ b/packages/sheets-data-validation/src/services/dv-formula.service.ts
@@ -16,12 +16,19 @@
import type { ISheetDataValidationRule, Nullable } from '@univerjs/core';
import type { IFormulaInfo, IOtherFormulaResult } from '@univerjs/engine-formula';
-import { DataValidationType, Disposable, Inject, isFormulaString, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
+import {
+ DataValidationType,
+ Disposable,
+ Inject,
+ isFormulaString,
+ IUniverInstanceService,
+ UniverInstanceType,
+} from '@univerjs/core';
import { DataValidationModel, DataValidatorRegistryService } from '@univerjs/data-validation';
import { OtherFormulaBizType, RegisterOtherFormulaService } from '@univerjs/engine-formula';
+import { Subject } from 'rxjs';
import { shouldOffsetFormulaByRange } from '../utils/formula';
import { DataValidationCacheService } from './dv-cache.service';
-import { DataValidationListCacheService } from './dv-list-cache.service';
type RuleId = string;
type UnitId = string;
@@ -29,16 +36,19 @@ type SubUnitId = string;
export class DataValidationFormulaService extends Disposable {
private _formulaRuleMap: Map<UnitId, Map<SubUnitId, Map<RuleId, [IFormulaInfo | undefined, IFormulaInfo | undefined]>>> = new Map();
+ private readonly _ruleFormulaResultChanged$ = new Subject<{ unitId: string; subUnitId: string; ruleId: string }>();
+
+ readonly ruleFormulaResultChanged$ = this._ruleFormulaResultChanged$.asObservable();
constructor(
@IUniverInstanceService private readonly _instanceService: IUniverInstanceService,
@Inject(RegisterOtherFormulaService) private _registerOtherFormulaService: RegisterOtherFormulaService,
@Inject(DataValidationCacheService) private readonly _dataValidationCacheService: DataValidationCacheService,
@Inject(DataValidationModel) private readonly _dataValidationModel: DataValidationModel,
- @Inject(DataValidatorRegistryService) private readonly _validatorRegistryService: DataValidatorRegistryService,
- @Inject(DataValidationListCacheService) private readonly _listCacheService: DataValidationListCacheService
+ @Inject(DataValidatorRegistryService) private readonly _validatorRegistryService: DataValidatorRegistryService
) {
super();
+ this.disposeWithMe(() => this._ruleFormulaResultChanged$.complete());
this._initFormulaResultHandler();
}
@@ -58,8 +68,7 @@ export class DataValidationFormulaService extends Disposable {
if (ruleId && formulaMap.get(ruleId)) {
const rule = this._dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
if (rule) {
- // Mark list cache dirty when formula result changes
- this._listCacheService.markRuleDirty(unitId, subUnitId, ruleId);
+ this._ruleFormulaResultChanged$.next({ unitId, subUnitId, ruleId });
this._dataValidationCacheService.markRangeDirty(unitId, subUnitId, rule.ranges);
}
}
diff --git a/packages/sheets-data-validation/src/services/dv-list-cache.service.ts b/packages/sheets-data-validation/src/services/dv-list-cache.service.ts
index d6110f031f..c505d26704 100644
--- a/packages/sheets-data-validation/src/services/dv-list-cache.service.ts
+++ b/packages/sheets-data-validation/src/services/dv-list-cache.service.ts
@@ -16,7 +16,7 @@
import type { ICellData, IDataValidationRule, Nullable } from '@univerjs/core';
import type { IOtherFormulaResult } from '@univerjs/engine-formula';
-import { Disposable, Inject, Injector, isFormulaString, numfmt } from '@univerjs/core';
+import { Disposable, Inject, isFormulaString, numfmt } from '@univerjs/core';
import { DataValidationModel } from '@univerjs/data-validation';
import { deserializeListOptions } from '@univerjs/sheets';
import { isLegalFormulaResult } from '../utils/formula';
@@ -43,11 +43,14 @@ export class DataValidationListCacheService extends Disposable {
private _cache: Map<UnitId, Map<SubUnitId, Map<RuleId, IListCacheItem>>> = new Map();
constructor(
- @Inject(Injector) private readonly _injector: Injector,
+ @Inject(DataValidationFormulaService) private readonly _formulaService: DataValidationFormulaService,
@Inject(DataValidationModel) private readonly _dataValidationModel: DataValidationModel
) {
super();
+ this.disposeWithMe(this._formulaService.ruleFormulaResultChanged$.subscribe(({ unitId, subUnitId, ruleId }) => {
+ this.markRuleDirty(unitId, subUnitId, ruleId);
+ }));
this._initRuleChangeListener();
}
@@ -75,9 +78,8 @@ export class DataValidationListCacheService extends Disposable {
return cached;
}
- const formulaService = this._injector.get(DataValidationFormulaService);
// Compute and cache
- const results = formulaService.getRuleFormulaResultSync(unitId, subUnitId, rule.uid);
+ const results = this._formulaService.getRuleFormulaResultSync(unitId, subUnitId, rule.uid);
return this.computeAndCache(unitId, subUnitId, rule, results);
}