Lifecycle
Global lifecycle
- Starting: Univer is initializing, and no business unit exists yet.
- Ready: The first business unit has been created. Later units 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 following Rendered. It does not wait for all asynchronous tasks.
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 stage has reached Ready, B still runs onReady(), but no second global Ready event is emitted.
A listener that you add may receive the current stage immediately, including Starting. To determine only which stage Univer is in, call univerAPI.getCurrentLifecycleStage() directly.
To remove a listener, dispose of the returned disposable object:
disposable.dispose()Plugin lifecycle hooks
A plugin runs onStarting() when it loads and then catches up to the current global stage. Loading B at different times shows how its hook calls compare with those of A.
Slowed down to show synchronous hook calls.
General plugins load at registration. A business-type plugin usually loads before the first unit of that type is created. If a new plugin is added to a type that has already started, it loads in a deferred batch. An explicit dependency can cause a plugin to load earlier.
Each batch calls hooks synchronously, one stage at a time and in dependency order, without waiting for asynchronous work. Confirm that the required unit, DOM element, or resource is ready before accessing it.
How is this guide?