Lifecycle
Global lifecycle
- Starting: Univer is initializing, 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. Asynchronous content may still be loading.
- Steady: The standard UI reaches this stage after a delay that follows Rendered. It does not wait for all asynchronous tasks to finish.
Facade API
const currentStage = univerAPI.getCurrentLifecycleStage()const disposable = univerAPI.addEvent(univerAPI.Event.LifeCycleChanged, ({ stage }) => { console.log(stage)})What the event reports
LifeCycleChanged reports the global stage of Univer. If plugin B is loaded after the global Ready, for example, B still runs onReady(), but no second global Ready event is emitted.
A listener added at any time may fire immediately with the current stage, including Starting. To determine the current stage only, call univerAPI.getCurrentLifecycleStage() directly.
To remove a listener, use the disposable object returned by the call:
disposable.dispose()Plugin lifecycle hooks
A plugin runs onStarting() when it loads and then advances to the global stage that Univer is in. The demo below changes when B loads and shows how its hook calls compare with A's.
Slowed down to show synchronous hook calls.
General plugins load when they are registered. Business-type plugins usually load before the first unit of that type is created. A new plugin for a type that has already started loads later, in a deferred batch. Explicit dependencies can load it earlier.
Hooks run synchronously within a batch, stage by stage and in dependency order. Nothing waits for asynchronous work inside a hook. Confirm that the unit, DOM element, or resource is actually ready before accessing it.
How is this guide?