coldbox-modules / cbwire

CBWIRE is a ColdBox module that makes building reactive, modern apps easy using HTML-over-the-wire technologies and CFML.
https://cbwire.ortusbooks.com
Other
28 stars 5 forks source link

Add onBoot Lifecycle Method in CBWIRE Components for Initial and Subsequent Renderings #128

Open grantcopley opened 11 months ago

grantcopley commented 11 months ago

Objective

To introduce an onBoot method in CBWIRE components that triggers during both the initial rendering and subsequent requests. This method will be useful for operations like security validation.

Details

Currently, CBWIRE components utilize the onMount() method, which is only executed during the component's initial rendering. The proposed onBoot method will extend this functionality to be executed on every request (initial and subsequent) of the component.

Example Use Case 1 - Security Validation

component extends="cbwire.models.Component" {
    function onBoot() {
        if ( !isLoggedIn() ) {
            return false;
        }
        return true;
    }
}

In this example, onBoot() performs a security check to see if the user is logged in. If the user is not logged in (isLoggedIn() returns false), the component will not render.

Example Use Case 2 - Data Loading

component extends="cbwire.models.Component" {
    function onBoot() {
       loadData();
        return true;
    }

    private function loadData() {
        // Logic for data loading
    }
}

Here, onBoot() is used for loading data every time the component is requested. This ensures that the component always has the latest data available, whether the initial load or a subsequent request.

Expected Functionality