Lifecycle Hooks
PtahJs exposes a synchronous pipeline through runtime.lifecycleChain.
Basic Usage
js
import { useRuntimeApp } from '@ptahjs/ui-vue';
import { LIFECYCLE_TYPE } from '@ptahjs/kernel';
const runtime = useRuntimeApp({ id: 've1' });
runtime.lifecycleChain.addStep(LIFECYCLE_TYPE.GET_PAGE_SCHEMA_DATA, (data) => {
return { ...data, exportedAt: Date.now() };
});API
| Method | Description |
|---|---|
addStep(type, fn) | Register a step |
removeStep(type, fn) | Remove a step |
clearSteps(type) | Clear steps by type |
clearAll() | Clear all steps |
process(type, data) | Execute the pipeline |
Lifecycle Types
BEFORE_TRANSFORM_DATAGET_PAGE_SCHEMA_DATARENDERER_MODULE_CONTENTRENDERER_MODULE_ITEM
Notes
- Steps run synchronously
- Steps run in registration order
- Returning
undefinedkeeps the previous value - Returning a
Promiseis ignored by the runtime
Example
js
runtime.lifecycleChain.addStep(LIFECYCLE_TYPE.BEFORE_TRANSFORM_DATA, (schema) => {
return schema;
});