CBWIRE
InstallSource CodeIssuesSupport
v2.x
v2.x
  • Introduction
  • Release History
    • What's New With 2.2
    • What's New With 2.1
    • What's New With 2.0
  • Getting Started
  • Examples
  • Essentials
    • Configuration
    • Wires
    • Data Properties
    • Computed Properties
      • Computed Properties ( Proxied )
    • Actions
    • Templates
    • Events & Listeners
    • Wire Lifecycle
    • JavaScript
    • Testing
  • Wire Features
    • Validation
    • File Uploads
    • Query String
    • Redirecting
    • Dependency Injection
  • Template Features
    • Directives
    • Loading States
    • Polling
    • Prefetching
    • Offline State
    • Defer Loading
    • Dirty State
  • Integrations
    • ContentBox CMS
    • Turbo
    • AlpineJS
    • Inline Scripts
Powered by GitBook
On this page
  • Order of Operations
  • onMount
  • onHydrate
  • onHydrate[ DataProperty ]
  • onRender

Was this helpful?

Export as PDF
  1. Essentials

Wire Lifecycle

Everything that has a beginning has an end. - The Oracle, Matrix

PreviousEvents & ListenersNextJavaScript

Last updated 2 years ago

Was this helpful?

Order of Operations

When a is initially loaded (before any background AJAX requests are performed), the Lifecycle Methods are executed in the following order.

  1. onMount()

  2. Render

  3. onRender() or implicit rendering

For background AJAX requests, lifecycle methods are executed in this order.

  1. onHydrate[DataProperty]()

  2. onHydrate()

  3. Render

  4. Execute

  5. onRender() or implicit rendering

onMount

Runs only once when the Wire is initially wired.

This does not fire during subsequent renderings for the Wire.

component extends="cbwire.models.Component" {

    data = {
        "taskId": 0
    };

    function onMount( event, rc, prc, parameters ){
        data.taskId = event.getValue( "taskId" );
    }

}

onMount() replaces what was formerly mount(). The mount() method is deprecated and will be removed in future major releases of CBWIRE.

onHydrate

component extends="cbwire.models.Component" {

    data = {
        "hydrated": false
    };

    function clicked() {}

    function onHydrate( data ) {
        // Note that computed properties are not rendered yet
        data.hydrated = true;
    }

    function onRender( args ) {
        return "
            <div>
                <div>Hydrated: #args.hydrated#</div>
                <button wire:click='clicked'>Click me</button>
            </div>
        ";
    }
}

onHydrate[ DataProperty ]

component extends="cbwire.models.Component" {

    data = {
        "count": 1
    };

    function onHydrateCount( data ) {
        // Note that computed properties are not rendered yet
        data.count += 1;
    }  
}

onRender

component extends="cbwire.models.Component" {

    data = {
        "rendered": true
    };
    
    computed = {
        "currentDate": function() {
            return now();
        }
    }

    function onRender( args ) {
        return "
            <div>
                <div>Rendered: #args.rendered# at #args.currentDate#</div>
            </div>
        ";
    }
}

Runs on subsequent requests, after the Wire is hydrated, but before are rendered, before an is performed, or before onRender() is called.

Runs on subsequent requests, after a specific is hydrated, but before are rendered, before an is performed, or before onRender() is called.

Runs during the rendering of a . If onRender() is defined on the Wire, CBWIRE will use what is returned as the component's template, otherwise it will perform a lookup for a view template. The args parameter is provided which contains both the and any rendered .

Wire
Computed Properties
Template
Computed Properties
Actions
Template
Computed Properties
Action
Data Property
Computed Properties
Action
Wire
Data Properties
Computed Properties