Lifecycle
Global lifecycle
- Starting: Initialization is in progress, and no business unit exists yet.
- Ready: The first business unit has been created. Units created later do not trigger this stage again.
- Rendered: The standard UI has completed its first render switch. This does not mean that all asynchronous content is ready.
- Steady: The standard UI enters this stage some time after Rendered. It does not wait for every asynchronous task.
Facade API
const currentStage = univerAPI.getCurrentLifecycleStage()const disposable = univerAPI.addEvent(univerAPI.Event.LifeCycleChanged, ({ stage }) => { console.log(stage)})What the event reports
LifeCycleChanged reports Univer's global stage. For example, when plugin B loads after the global stage has reached Ready, B runs its onReady(), but no second global Ready event is emitted.
When a listener is added, its callback may receive the current stage immediately, including Starting. To obtain only the current stage, call univerAPI.getCurrentLifecycleStage() directly.
To remove a listener, use the returned disposable object:
disposable.dispose()Plugin lifecycle hooks
A plugin runs onStarting() when it loads, then catches up to the current global stage. Control the stage at which B loads in order to compare its hook calls with those of A.
Slowed down to show synchronous hook calls.
General plugins load on registration. Business-type plugins usually load before the first unit of that type is constructed. New plugins for a type that has already started load in a deferred batch. Explicit dependencies can trigger earlier loading.
Hooks in the same batch are called synchronously, stage by stage and in dependency order, and Univer does not wait for asynchronous tasks inside them. Confirm that the specific unit, DOM element, or resource is ready before accessing it.
How is this guide?