arrow-left
All pages
gitbookPowered by GitBook
1 of 1

Loading...

Computed Properties ( Proxied )

Create dynamic properties for your UI Wires.

circle-exclamation

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

Otherwise, please follow this guide instead.

circle-check

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.

hashtag
Defining Properties

Define Computed Properties in your using computed.

hashtag
Accessing From Actions

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

hashtag
Accessing From Templates

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

Data Properties
Wires
Actions
Template
component extends="cbwire.models.Component" {

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

    // Computed Properties
    computed = {
        "allTasks": function() {
            return taskService.getAll();
        }
    };
}
component extends="cbwire.models.Component" {

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

    // Action
    function deleteTasks() {      

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

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