Skip to main content

Lifecycle

Each node can run callbacks while Qore handles a node request and while it prepares the node response.

Use request callbacks for incoming state, such as button clicks or form interactions. Use response callbacks for derived output, such as table pagination, disabled dates or final node properties.

Node callback order

Request pass

  1. 1
    Node$node->onNodeRequest()current node
    Callbacks registered on the current node run in registration order. On the initial request, default visibility is applied immediately before them.
  2. 2
    Node$child->onNodeRequest()each child
    The first child's complete subtree runs parent-first, then the next sibling's subtree runs.

Response pass

  1. 3
    Node$node->onNodeResponse()current node
    After the entire request pass has finished, callbacks on the current node run in registration order.
  2. 4
    Node$child->onNodeResponse()each child
    The first child's complete subtree runs parent-first, then the next sibling's subtree runs.

Finish

  1. 5
    Node$root->setOnBeforeResponseCallback()root only
    The optional root callback runs once, after both complete tree passes.
  2. 6
    FrameworkNodeManager::toArray()
    The visible tree and response state are serialized, then the node registrar is cleared.
Example tree orderroot.request → child.request → grandchild.request → root.response → child.response → grandchild.response → root.beforeResponse → serialize

Hidden nodes still run request and response callbacks. Visibility only removes them during serialization.

On Node Request

Runs before serialization, while the backend is handling incoming node state. For example, ButtonNode checks whether the user clicked it:

$myNode->onNodeRequest(function (NodeManager $manager) {
if (! $manager->getStateByKey($this->id)) {
return;
}

$listener = $this->onClickListener;
$listener(new ClickEvent($this, $manager));
});

On Node Response

Runs after request callbacks and before serialization.

For example, EloquentTableNode uses this stage to handle pagination, sorting and filtering:

$myNode->onNodeResponse(function (NodeManager $nodeManager) {
$this->handleTableResponse($nodeManager);
});

Fields inside a FormNode add form-specific callbacks between the normal node request and response passes. See Field Lifecycle for their complete order.