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.

docs: update doc on runLifecycle (#1740)

Wenzhao Hu52c0b6e4b7f3
diff --git a/packages/core/src/services/lifecycle/lifecycle.ts b/packages/core/src/services/lifecycle/lifecycle.ts
index 103173d301..d0e06f395d 100644
--- a/packages/core/src/services/lifecycle/lifecycle.ts
+++ b/packages/core/src/services/lifecycle/lifecycle.ts
@@ -52,7 +52,24 @@ export const LifecycleNameMap = {
export const LifecycleToModules = new Map<LifecycleStages, Array<DependencyIdentifier<unknown>>>();
/**
- * Register some modules here that will automatically run when Univer progressed to a certain lifecycle stage
+ * Register the decorated class to be automatically instantiated when Univer progresses to the certain lifecycle stage.
+ *
+ * @param lifecycleStage The lifecycle stage to instantiate this class.
+ * @param identifier The dependency identifier of the class. Usually, it is the class itself unless you bind this class
+ * with another injection identifier.
+ *
+ *
+ * @example
+ * // Ignore the `\` below. This is JSDoc's bug.
+ * \@OnLifecycle(LifecycleStages.Ready, MyService)
+ * class MyService {
+ * }
+ *
+ * @example
+ * // Ignore the `\` below. This is JSDoc's bug.
+ * \@OnLifecycle(LifecycleStages.Rendered, IMyService)
+ * class MyService implements IMyService {
+ * }
*/
export function OnLifecycle(lifecycleStage: LifecycleStages, identifier: DependencyIdentifier<unknown>) {
const decorator = function decorator(_: Ctor<unknown>) {
@@ -62,6 +79,19 @@ export function OnLifecycle(lifecycleStage: LifecycleStages, identifier: Depende
return decorator;
}
+/**
+ * Register a dependency to be automatically instantiated when Univer progresses to the certain lifecycle stage.
+ *
+ * @param lifecycleStage The lifecycle stage to instantiate this dependency.
+ * @param identifier The dependencies' identifier. **Beware** that if the dependency (e.g. a class) is bound to an
+ * identifier, you should register the identifier instead of the dependency itself.
+ *
+ * @example
+ * runOnLifecycle(LifecycleStages.Ready, MyService);
+ *
+ * @example
+ * runOnLifecycle(LifecycleStages.Rendered, IMyService);
+ */
export function runOnLifecycle(lifecycleStage: LifecycleStages, identifier: DependencyIdentifier<unknown>) {
if (!LifecycleToModules.has(lifecycleStage)) {
LifecycleToModules.set(lifecycleStage, []);