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
  • Basic Example
  • Scaffolding

Was this helpful?

Export as PDF
  1. Essentials

Wires

Wires are reactive UI elements you create. They include a powerful feature-set provided by CBWIRE.

PreviousConfigurationNextData Properties

Last updated 2 years ago

Was this helpful?

Wires primarily consist of the following:

  • Reactive properties that we can easily change.

  • Properties that are computed every time our template is rendered.

  • Methods that make state changes to our data properties.

  • Listen for emitted events within Wires or client-side JavaScript.

  • HTML to render our Wire.

Basic Example

// File: wires/TaskList.cfc
component extends="cbwire.models.Component" {

    // Data properties
    data = {
        "task": "",
        "tasks": []
    };
    
    // Computed properties
    computed = {
        "counter": function() {
            return arrayLen( data.tasks );
        }
    };
    
    // Listeners
    listeners = {
        "taskAdded": "sendEmail"
    };
    
    // Action
    function addTask(){
        data.tasks.append( data.task );
        this.emit( "taskAdded", data.task );
    }
    
}
<!--- /views/wires/tasklist.cfm --->
<cfoutput>
<div>
    <div>Number of tasks: #args.computed.counter()#</div>
    <div><input wire:model="task"></div>
    <div><button wire:click="addTask">Add Task</button></div>
</div>
</cfoutput>

Scaffolding

From our CommandBox shell, type:

install commandbox-cbwire

Let's create a Counter Wire that we will use to list our favorite movies.

cbwire create Counter
// Created /wires/Counter.cfc
// Created /views/wires/counter.cfm
// Created /tests/specs/integration/wires/CounterTest.cfc

You can provide named arguments as well.

cbwire create name=Counter views=false
// Created /wires/Counter.cfc
// Created /tests/specs/integration/wires/CounterTest.cfc

You can scaffold Wires quickly using the module.

Data Properties
Computed Properties
Actions
Events and Listeners
Templates
commandbox-cbwire