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: fix univer business object lifecycle

Wenzhao Huf460e3b80b91
diff --git a/packages/core/src/Basics/Univer.ts b/packages/core/src/Basics/Univer.ts
index d447998160..66e32ed2ae 100644
--- a/packages/core/src/Basics/Univer.ts
+++ b/packages/core/src/Basics/Univer.ts
@@ -90,15 +90,16 @@ export class Univer {
if (!this._univerSheet) {
this._univerSheet = this._rootInjector.createInstance(UniverSheet);
-
this._univerPluginRegistry
.getRegisterPlugins(PluginType.Sheet)
.forEach((p) => this._univerSheet!.addPlugin(p.plugin as unknown as PluginCtor<any>, p.options));
this._tryStart();
+ this._univerSheet.start();
+
addSheet();
- this._univerSheet.init();
this._tryProgressToReady();
+ this._univerSheet.ready();
} else {
addSheet();
}
@@ -115,15 +116,16 @@ export class Univer {
if (!this._univerDoc) {
this._univerDoc = this._rootInjector.createInstance(UniverDoc);
-
this._univerPluginRegistry
.getRegisterPlugins(PluginType.Doc)
.forEach((p) => this._univerDoc!.addPlugin(p.plugin as unknown as PluginCtor<any>, p.options));
this._tryStart();
- this._univerDoc.init();
+ this._univerDoc.start();
+
addDoc();
this._tryProgressToReady();
+ this._univerDoc.ready();
} else {
addDoc();
}
@@ -145,7 +147,7 @@ export class Univer {
.getRegisterPlugins(PluginType.Slide)
.forEach((p) => this._univerSlide!.addPlugin(p.plugin as unknown as PluginCtor<any>, p.options));
this._tryStart();
- this._univerSlide.init();
+ this._univerSlide.ready();
addSlide();
this._tryProgressToReady();
diff --git a/packages/core/src/Basics/UniverDoc.ts b/packages/core/src/Basics/UniverDoc.ts
index 1f189271c1..fc43b970cb 100644
--- a/packages/core/src/Basics/UniverDoc.ts
+++ b/packages/core/src/Basics/UniverDoc.ts
@@ -20,18 +20,18 @@ export class UniverDoc extends Disposable {
super();
}
- init(): void {
+ start(): void {
+ this._pluginStore.forEachPlugin((p) => p.onStarting(this._injector));
+ this._initService.initModulesOnStage(LifecycleStages.Starting);
+ }
+
+ ready(): void {
this.disposeWithMe(
toDisposable(
this._injector
.get(LifecycleService)
.subscribeWithPrevious()
.subscribe((stage) => {
- if (stage === LifecycleStages.Starting) {
- this._pluginStore.forEachPlugin((p) => p.onStarting(this._injector));
- this._initService.initModulesOnStage(LifecycleStages.Starting);
- }
-
if (stage === LifecycleStages.Ready) {
this._pluginStore.forEachPlugin((p) => p.onReady());
this._initService.initModulesOnStage(LifecycleStages.Ready);
@@ -57,7 +57,9 @@ export class UniverDoc extends Disposable {
return this._injector.createInstance(DocumentModel, docData);
}
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
addPlugin<T extends Plugin>(pluginCtor: PluginCtor<T>, options: any): void {
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
const pluginInstance: Plugin = this._injector.createInstance(pluginCtor as unknown as Ctor<any>, options);
pluginInstance.onStarting(this._injector);
this._pluginStore.addPlugin(pluginInstance);
diff --git a/packages/core/src/Basics/UniverSheet.ts b/packages/core/src/Basics/UniverSheet.ts
index 635b4fc70e..438ff46aed 100644
--- a/packages/core/src/Basics/UniverSheet.ts
+++ b/packages/core/src/Basics/UniverSheet.ts
@@ -24,19 +24,18 @@ export class UniverSheet extends Disposable implements IDisposable {
this._initDependencies(_injector);
}
- init(): void {
+ start(): void {
+ this._pluginStore.forEachPlugin((p) => p.onStarting(this._injector));
+ this._initService.initModulesOnStage(LifecycleStages.Starting);
+ }
+
+ ready(): void {
this.disposeWithMe(
toDisposable(
this._injector
.get(LifecycleService)
.subscribeWithPrevious()
.subscribe((stage) => {
- if (stage === LifecycleStages.Starting) {
- this._pluginStore.forEachPlugin((p) => p.onStarting(this._injector));
- this._initService.initModulesOnStage(LifecycleStages.Starting);
- return;
- }
-
if (stage === LifecycleStages.Ready) {
this._pluginStore.forEachPlugin((p) => p.onReady());
this._initService.initModulesOnStage(LifecycleStages.Ready);
diff --git a/packages/core/src/Basics/UniverSlide.ts b/packages/core/src/Basics/UniverSlide.ts
index 5f76d54896..770ed72fac 100644
--- a/packages/core/src/Basics/UniverSlide.ts
+++ b/packages/core/src/Basics/UniverSlide.ts
@@ -21,16 +21,15 @@ export class UniverSlide extends Disposable {
super();
}
- init(): void {
+ start(): void {
+ this._pluginStore.forEachPlugin((p) => p.onStarting(this._injector));
+ this._initializerService.initModulesOnStage(LifecycleStages.Starting);
+ }
+
+ ready(): void {
this.disposeWithMe(
toDisposable(
this._lifecycleService.subscribeWithPrevious().subscribe((stage) => {
- if (stage === LifecycleStages.Starting) {
- this._pluginStore.forEachPlugin((p) => p.onStarting(this._injector));
- this._initializerService.initModulesOnStage(LifecycleStages.Starting);
- return;
- }
-
if (stage === LifecycleStages.Ready) {
this._pluginStore.forEachPlugin((p) => p.onReady());
this._initializerService.initModulesOnStage(LifecycleStages.Ready);
@@ -65,7 +64,9 @@ export class UniverSlide extends Disposable {
*
* @internal
*/
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
addPlugin<T extends Plugin>(plugin: PluginCtor<T>, options: any): void {
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
const pluginInstance: Plugin = this._injector.createInstance(plugin as unknown as Ctor<any>, options);
this._pluginStore.addPlugin(pluginInstance);
}