import type { ApplicationService } from '@adonisjs/core/types'; import type ComponentContext from './component_context.js'; import { type Component } from './component.js'; /** * Base class for all Livewire features (hooks) * Features can hook into various lifecycle events of components */ export default abstract class ComponentHook { /** * The component instance this hook is attached to */ component: Component; /** * The application service instance */ app: ApplicationService; /** * Optionally set the component and app at construction time, for * ComponentHook subclasses (features) instantiated directly with both * available. `Decorator` subclasses — instantiated eagerly at * class-decoration time, before any component or app exists — must * continue calling bare `super()` and rely on `__boot(component)` * instead; both params are optional specifically so that keeps working * unmodified. */ constructor(component?: Component, app?: ApplicationService); /** * Set the component instance */ setComponent(component: Component): void; /** * Set the application service instance */ setApp(app: ApplicationService): void; /** * Dispatch a lifecycle event to this component hook */ dispatch(event: string, ...params: any[]): Promise; /** * Call the boot lifecycle hook if it exists */ callBoot(...params: any[]): Promise; /** * Call the mount lifecycle hook if it exists */ callMount(...params: any[]): Promise; /** * Call the hydrate lifecycle hook if it exists */ callHydrate(...params: any[]): Promise; /** * Call the update lifecycle hook if it exists */ callUpdate(propertyName: string, fullPath: string, newValue: any): Promise<(...params: any[]) => Promise>; /** * Call the call lifecycle hook if it exists (before method execution) * @param method - The method name being called * @param params - The parameters for the method * @param returnEarly - Function to return early from the method call * @param metadata - Optional metadata about the call * @param componentContext - Optional component context */ callCall(method: string, params: any[], returnEarly: (value?: any) => void, metadata?: any, componentContext?: ComponentContext): Promise; /** * Call the render lifecycle hook if it exists */ callRender(...params: any[]): Promise<(...args: any[]) => Promise>; /** * Call the renderIsland lifecycle hook if it exists * PHP parity: callRenderIsland */ callRenderIsland(...params: any[]): Promise<(...args: any[]) => Promise>; /** * Call the dehydrate lifecycle hook if it exists */ callDehydrate(...params: any[]): Promise; /** * Call the destroy lifecycle hook if it exists */ callDestroy(...params: any[]): Promise; /** * Call the exception lifecycle hook if it exists */ callException(...params: any[]): Promise; /** * Get all properties from the component * PHP parity: returns $this->component->all() */ getProperties(): Record; /** * Get a specific property from the component * Supports dot notation for nested properties (PHP parity: data_get) * @param name - Property name, supports dot notation (e.g., 'user.name') */ getProperty(name: string): any; /** * Set a value in the component's store */ storeSet(key: string, value: any): void; /** * Push a value to an array in the component's store */ storePush(key: string, value: any, iKey?: string): void; /** * Get a value from the component's store */ storeGet(key: string, defaultValue?: any): any; /** * Check if a key exists in the component's store */ storeHas(key: string): boolean; /** * Optional boot lifecycle hook * Called once when the component is first initialized * Override this method in subclasses to implement boot logic */ boot?(...params: any[]): Promise; /** * Optional mount lifecycle hook * Called when the component is mounted with initial parameters * Override this method in subclasses to implement mount logic */ mount?(...params: any[]): Promise; /** * Optional hydrate lifecycle hook * Called when the component is hydrated from a snapshot * Override this method in subclasses to implement hydrate logic */ hydrate?(...params: any[]): Promise; /** * Optional dehydrate lifecycle hook * Called when the component state is being serialized * Override this method in subclasses to implement dehydrate logic */ dehydrate?(...params: any[]): Promise; /** * Optional destroy lifecycle hook * Called when the component is being destroyed * Override this method in subclasses to implement destroy logic */ destroy?(...params: any[]): Promise; /** * Optional exception lifecycle hook * Called when an exception occurs in the component * Override this method in subclasses to implement exception handling */ exception?(...params: any[]): Promise; /** * Optional call lifecycle hook * Called before a component method is executed * Override this method in subclasses to implement call logic * @param method - The method name being called * @param params - The parameters for the method * @param returnEarly - Function to return early from the method call, or boolean for compatibility * @param metadata - Optional metadata about the call * @param componentContext - Optional component context */ call?(method: string, params: any[], returnEarly?: (value?: any) => void | boolean, metadata?: any, componentContext?: ComponentContext): Promise; /** * Optional update lifecycle hook * Called when a component property is being updated * Override this method in subclasses to implement update logic * @param propertyName - The name of the property being updated * @param fullPath - The full path to the property (for nested properties) * @param newValue - The new value being set * @returns Optional callback function to execute after the update */ update?(propertyName: string, fullPath: string, newValue: any): Promise; /** * Optional render lifecycle hook * Called when the component is being rendered * Override this method in subclasses to implement render logic * @returns Optional callback function to execute after rendering */ render?(...params: any[]): Promise; /** * Optional renderIsland lifecycle hook * Called when rendering an island component * PHP parity: renderIsland * @returns Optional callback function to execute after rendering */ renderIsland?(...params: any[]): Promise; }