CBWIRE
v4.x
v4.x
  • Introduction
  • How It Works
  • Getting Started
  • Configuration
  • Releases
    • What's New With 4.1
    • What's New With 4.0
    • What's New With 3.2
    • What's New With 3.1
    • What's New With 3.0
    • What's New With 2.2
    • What's New With 2.1
    • What's New With 2.0
  • Resources
  • Upgrading from CBWIRE 3.x
  • Upgrading from CBWIRE 2.x
  • CBWIRE CLI
  • The Essentials
    • Components
    • Templates
    • Data Properties
    • Computed Properties
    • Data Binding
    • Actions
    • Events
    • Nesting Components
    • Lifecycle Methods
    • JavaScript
    • Testing
  • Features
    • Single-file Components
    • Alpine.js
    • Lazy Loading
    • Form Validation
    • File Uploads
    • Query String
    • Redirecting
    • WireBox
  • Template Directives
    • wire:click
    • wire:confirm
    • wire:dirty
    • wire:ignore
    • wire:init
    • wire:key
    • wire:loading
    • wire:model
    • wire:navigate
    • wire:offline
    • wire:poll
    • wire:stream
    • wire:submit
    • wire:transition
  • Advanced
    • Troubleshooting
Powered by GitBook
On this page
  • Overview
  • Order Of Operations
  • Methods
  • onMount
  • onRender
  • onHydrate
  • onHydrate[ Property ]
  • onUpdate
  • onUpdate[ Property ]

Was this helpful?

Export as PDF
  1. The Essentials

Lifecycle Methods

PreviousNesting ComponentsNextJavaScript

Last updated 7 months ago

Was this helpful?

Overview

CBWIRE provides lifecycle methods you can hook into to update and render your .

Order Of Operations

The lifecycle methods are executed in the following order when a component is initially loaded:

  1. onMount()

  2. onRender()

Lifecycle methods are executed in this order for subsequent AJAX requests.

  1. onHydrate[DataProperty]()

  2. onHydrate()

  3. onUpdate[DataProperty]()

  4. onUpdate()

  5. Fire actions

  6. onRender()

Methods

onMount

It runs only once when a component is initially wired. This can inject data values into your component via params you pass in when calling wire(), or pulling in values from the RC or PRC scopes.

component extends="cbwire.models.Component" {
    data = {
        "someValue: ""
    };
    function onMount( event, rc, prc, params ){
        data.someValue = params.someValue;
    }
}

onMount() only fires when the component is initially rendered and does not fire on subsequent requests when your component re-renders. This can cause issues referencing things such as the RC or PRC scope. If you pass in values with the RC or PRC scope, you must store them as data properties to ensure they are available to your component in subsequent requests.

onRender

It runs on all requests before rendering your component. This gives you more control if needed when rendering. There is also a renderIt() alias, which does the same.

component extends="cbwire.models.Component" {
    function onRender() {
        return "<div>direct html</div>;
        // return template( _getViewPath() ); // CBWIRE's default method
        // return template( "some.custom.path" );
    }
}

onHydrate

component extends="cbwire.models.Component" {
    function onHydrate( data ) {
        // Note that computed properties have not yet rendered
        data.hydrated = true;
    }
}

onHydrate[ Property ]

Runs on subsequent requests after a specific data property is hydrated but before computed properties are rendered, before an action is performed, or before the component is rendered.

component extends="cbwire.models.Component" {
    data = {
        "count": 1
    };
    function onHydrateCount( data ) {
        // Note that computed properties have not yet rendered
        data.count += 1;
    }  
}

onUpdate

component extends="cbwire.models.Component" {
    function onUpdate( newValues, oldValues ) {
        // ....
    }
}

onUpdate() will only fire if the incoming request updates a single data property, such as when using wire:model.

onUpdate[ Property ]

component extends="cbwire.models.Component" {
    data = {
        "count": 1
    };
    function onUpdateCount( newValue, oldValue ) {
        if ( newValue >= 100 ) {
            // Reset back to 1
            data.count = 1;
        }

    }
}

Runs on subsequent requests after a component is hydrated but before are rendered, before a is updated or is performed, or before the component is rendered.

Runs on subsequent requests after any is updated using wire:model or $set.

Runs on subsequent requests after a is updated using wire:model or $set. It only runs when the targeted data property is updated.

components
computed properties
data property
action
data property
data property