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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
refactor: remove unsync mutations
Wenzhao Hu23c6ff2cc7d1
diff --git a/examples/src/sheets/main.ts b/examples/src/sheets/main.tsindex fab96bfbf2..995c55ca15 100644--- a/examples/src/sheets/main.ts+++ b/examples/src/sheets/main.ts@@ -16,7 +16,7 @@import { LocaleType, LogLevel, Univer } from '@univerjs/core';import { defaultTheme } from '@univerjs/design';-import { RichTextEditingMutation, UniverDocsPlugin } from '@univerjs/docs';+import { UniverDocsPlugin } from '@univerjs/docs';import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula';import { UniverRenderEnginePlugin } from '@univerjs/engine-render';import type { IUniverRPCMainThreadConfig } from '@univerjs/rpc';@@ -66,7 +66,6 @@ univer.registerPlugin(UniverFormulaEnginePlugin, {univer.registerPlugin(UniverSheetsFormulaPlugin);univer.registerPlugin(UniverRPCMainThreadPlugin, {workerURL: './worker.js',- unsyncMutations: new Set([RichTextEditingMutation.id]),} as IUniverRPCMainThreadConfig);// create univer sheet instancediff --git a/packages/rpc/src/controllers/data-sync/data-sync-primary.controller.ts b/packages/rpc/src/controllers/data-sync/data-sync-primary.controller.tsindex aa52c2f04a..6105d14cc1 100644--- a/packages/rpc/src/controllers/data-sync/data-sync-primary.controller.ts+++ b/packages/rpc/src/controllers/data-sync/data-sync-primary.controller.ts@@ -44,9 +44,9 @@ import { fromModule, toModule } from '../../services/rpc/rpc.service';@OnLifecycle(LifecycleStages.Starting, DataSyncPrimaryController)export class DataSyncPrimaryController extends RxDisposable {private _remoteInstanceService!: IRemoteInstanceService;+ private readonly _syncingUnits = new Set<string>();constructor(- private readonly _unsyncMutations: Set<string>,@Inject(Injector) private readonly _injector: Injector,@ICommandService private readonly _commandService: ICommandService,@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,@@ -75,6 +75,7 @@ export class DataSyncPrimaryController extends RxDisposable {private _init(): void {this._univerInstanceService.sheetAdded$.pipe(takeUntil(this.dispose$)).subscribe((sheet) => {+ this._syncingUnits.add(sheet.getUnitId());// If a sheet is created, it should sync the data to the worker thread.this._remoteInstanceService.createInstance({unitID: sheet.getUnitId(),@@ -84,6 +85,7 @@ export class DataSyncPrimaryController extends RxDisposable {});this._univerInstanceService.sheetDisposed$.pipe(takeUntil(this.dispose$)).subscribe((workbook) => {+ this._syncingUnits.delete(workbook.getUnitId());// If a sheet is disposed, it should sync the data to the worker thread.this._remoteInstanceService.disposeInstance({unitID: workbook.getUnitId(),@@ -93,14 +95,16 @@ export class DataSyncPrimaryController extends RxDisposable {this.disposeWithMe(// Mutations executed on the main thread should be synced to the worker thread.this._commandService.onCommandExecuted((commandInfo, options) => {+ const { type, params } = commandInfo;+ const unitID = (params as any).unitId || ''; // TODO@wzhudev: use a universal way to get unitIdif (- commandInfo.type === CommandType.MUTATION &&- !(options as IRemoteSyncMutationOptions)?.fromSync &&- !this._unsyncMutations.has(commandInfo.id)+ // only sync mutations to the worker thread+ type === CommandType.MUTATION &&+ (!unitID || this._syncingUnits.has(unitID)) &&+ // do not sync mutations from the web worker back to the web worker+ !(options as IRemoteSyncMutationOptions)?.fromSync) {- this._remoteInstanceService.syncMutation({- mutationInfo: commandInfo as IMutationInfo,- });+ this._remoteInstanceService.syncMutation({ mutationInfo: commandInfo as IMutationInfo });}}));diff --git a/packages/rpc/src/plugin.ts b/packages/rpc/src/plugin.tsindex 347e8dbc0f..aa2f4a38aa 100644--- a/packages/rpc/src/plugin.ts+++ b/packages/rpc/src/plugin.ts@@ -34,7 +34,6 @@ import {export interface IUniverRPCMainThreadConfig {workerURL: string | URL;- unsyncMutations?: Set<string>;}/**@@ -61,13 +60,7 @@ export class UniverRPCMainThreadPlugin extends Plugin {useFactory: () => new ChannelService(messageProtocol),},],- [- DataSyncPrimaryController,- {- useFactory: () =>- injector.createInstance(DataSyncPrimaryController, this._config?.unsyncMutations ?? new Set()),- },- ],+ [DataSyncPrimaryController],[IRemoteSyncService, { useClass: RemoteSyncPrimaryService }],];