Skip to content

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

MethodDescription
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_DATA
  • GET_PAGE_SCHEMA_DATA
  • RENDERER_MODULE_CONTENT
  • RENDERER_MODULE_ITEM

Notes

  • Steps run synchronously
  • Steps run in registration order
  • Returning undefined keeps the previous value
  • Returning a Promise is ignored by the runtime

Example

js
runtime.lifecycleChain.addStep(LIFECYCLE_TYPE.BEFORE_TRANSFORM_DATA, (schema) => {
    return schema;
});