Skip to content

Commit

Permalink
feat: update
Browse files Browse the repository at this point in the history
  • Loading branch information
weird94 committed Nov 23, 2024
1 parent 487bc1a commit a489c7c
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions packages/sheets-data-validation/src/services/dv-cache.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
*/

import type { DataValidationStatus, IRange, ISheetDataValidationRule, Nullable } from '@univerjs/core';
import { Disposable, ICommandService, Inject, ObjectMatrix, Range } from '@univerjs/core';
import { type ISetRangeValuesMutationParams, SetRangeValuesMutation } from '@univerjs/sheets';
import type { IRemoveSheetMutationParams, ISetRangeValuesMutationParams } from '@univerjs/sheets';
import { Disposable, ICommandService, Inject, IUniverInstanceService, ObjectMatrix, Range, UniverInstanceType } from '@univerjs/core';
import { RemoveSheetMutation, SetRangeValuesMutation } from '@univerjs/sheets';
import { Subject } from 'rxjs';

export class DataValidationCacheService extends Disposable {
Expand All @@ -26,10 +27,12 @@ export class DataValidationCacheService extends Disposable {
readonly dirtyRanges$ = this._dirtyRanges$.asObservable();

constructor(
@Inject(ICommandService) private readonly _commandService: ICommandService
@Inject(ICommandService) private readonly _commandService: ICommandService,
@Inject(IUniverInstanceService) private readonly _univerInstanceService: IUniverInstanceService
) {
super();
this._initDirtyRanges();
this._initSheetRemove();
}

private _initDirtyRanges() {
Expand All @@ -45,6 +48,21 @@ export class DataValidationCacheService extends Disposable {
}));
}

private _initSheetRemove() {
this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
if (commandInfo.id === RemoveSheetMutation.id) {
const { unitId, subUnitId } = commandInfo.params as IRemoveSheetMutationParams;
this._cacheMatrix.get(unitId)?.delete(subUnitId);
}
}));

this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe((univerInstance) => {
if (univerInstance.type === UniverInstanceType.UNIVER_SHEET) {
this._cacheMatrix.delete(univerInstance.getUnitId());
}
}));
}

private _ensureCache(unitId: string, subUnitId: string) {
let unitMap = this._cacheMatrix.get(unitId);

Expand Down

0 comments on commit a489c7c

Please sign in to comment.