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.

feat(facade): add manual initialization support (#6022)

Univerddefdfb6d601
diff --git a/packages/core/src/facade/f-base.ts b/packages/core/src/facade/f-base.ts
index 8c94756ef7..01ccceb524 100644
--- a/packages/core/src/facade/f-base.ts
+++ b/packages/core/src/facade/f-base.ts
@@ -48,6 +48,10 @@ export abstract class FBase extends Disposable {
* @ignore
*/
const InitializerSymbol = Symbol('initializers');
+/**
+ * @ignore
+ */
+const ManualInitSymbol = Symbol('manualInit');
/**
* @ignore
@@ -66,6 +70,10 @@ export class FBaseInitialable extends Disposable {
) {
super();
+ const Ctor = this.constructor as any;
+ const manual = Boolean(Ctor[ManualInitSymbol]); // <— Enable manual control only when this class (and its subclasses) is active.
+ if (manual) return;
+
// eslint-disable-next-line ts/no-this-alias
const self = this;
@@ -80,7 +88,18 @@ export class FBaseInitialable extends Disposable {
/**
* @ignore
*/
- _initialize(injector: Injector): void { }
+ _initialize(injector: Injector, ..._rest: any[]): void { }
+
+ protected _runInitializers(...args: any[]): void {
+ const initializers = Object.getPrototypeOf(this)[InitializerSymbol];
+ if (initializers?.length) {
+ initializers.forEach((fn: any) => fn.apply(this, args));
+ }
+ }
+
+ protected static _enableManualInit(): void {
+ (this as any)[ManualInitSymbol] = true;
+ }
/**
* @ignore
diff --git a/packages/sheets/src/facade/f-range.ts b/packages/sheets/src/facade/f-range.ts
index 879af94a80..8f8b1a126f 100644
--- a/packages/sheets/src/facade/f-range.ts
+++ b/packages/sheets/src/facade/f-range.ts
@@ -45,6 +45,8 @@ export type GetStyleType = 'row' | 'col' | 'cell';
* @hideconstructor
*/
export class FRange extends FBaseInitialable {
+ static { this._enableManualInit(); }
+
constructor(
protected readonly _workbook: Workbook,
protected readonly _worksheet: Worksheet,
@@ -54,6 +56,15 @@ export class FRange extends FBaseInitialable {
@Inject(FormulaDataModel) protected readonly _formulaDataModel: FormulaDataModel
) {
super(_injector);
+
+ this._runInitializers(
+ this._injector,
+ this._workbook,
+ this._worksheet,
+ this._range,
+ this._commandService,
+ this._formulaDataModel
+ );
}
/**