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
  • Defining Properties
  • Accessing From Actions
  • Accessing From Templates

Was this helpful?

Export as PDF
  1. Essentials
  2. Computed Properties

Computed Properties ( Proxied )

Create dynamic properties for your UI Wires.

PreviousComputed PropertiesNextActions

Last updated 2 years ago

Was this helpful?

You must be on CBWIRE version 2.3.5 or later and enable the setting useComputedPropertiesProxy to follow this guide.

Otherwise, please follow instead.

In CBWIRE 2.3.5, we introduced the ability to proxy Computed Properties, which offers several advantages, including:

  • Computed Properties are passed around as closures and are only rendered when called.

  • The ability to invoke Computed Properties anywhere they are needed (both Actions and Templates).

  • The ability to cache Computed Property results to enhance performance.

Computed Properties are dynamic properties and help derive values from a database or another persistent store like a cache.

Computed Properties are similar to with some key differences:

  • They are declared as inline functions using computed.

  • They can return any CFML value or object.

Defining Properties

Define Computed Properties in your using computed.

component extends="cbwire.models.Component" {

    property name="taskService" inject="taskService@myapp";

    // Computed Properties
    computed = {
        "allTasks": function() {
            return taskService.getAll();
        }
    };
}

Accessing From Actions

component extends="cbwire.models.Component" {

    // Computed Properties
    computed = {
        "allTasks": function() {
            // return something here
        }
    };

    // Action
    function deleteTasks() {      

        if ( arrayLen( computed.allTasks() ) {
            taskService.deleteAll();
        }

    }
}

Accessing From Templates

<cfoutput>
<div>
    <ul>
        <cfloop array="#args.computed.allTasks()#" index="task">
            <li>#task#</li>    
        </cfloop>
    </ul>
</div>
</cfoutput>

You can access your Computed Properties from within your using computed.[propertyName]().

You can access Computed Properties in your using args.computed.[computedProperty]().

Configuration
this guide
Data Properties
Wires
Actions
Template