Data Properties

Data Properties hold the state of your component and are defined with a data structure. Each data property is assigned a default value and is automatically synchronized between server and client.

Data properties are reactive - when an action modifies a property, CBWIRE automatically re-renders only the affected parts of your template. They can hold strings, numbers, booleans, dates, arrays, and structures, and are directly accessible in templates without special syntax.

//./wires/SomeComponent.bx
class extends="cbwire.models.Component" {
    data = {
        "propertyName": "defaultValue"
    };
}

Accessing From Actions

Using the data structure, you can access data properties from within your component actions.

Accessing From Templates

You can access data properties within your templates using #propertyName#.

Nested Properties

Organize related data using nested structures and access them with dot notation. This keeps your data organized hierarchically instead of flattening everything into top-level properties.

Accessing in Templates

Reference nested properties using dot notation in wire:model and other directives:

Accessing in Actions

Use dot notation to access and modify nested properties in your component methods:

Lifecycle Hooks

Lifecycle hooks for nested properties use underscores instead of dots. A property path like user.name.first triggers onUpdateuser_name_first():

Missing nested keys are created automatically. If data.user doesn't have a preferences key, setting data.user.preferences.theme = "dark" creates the structure automatically.

Resetting Properties

You can reset all data properties to their original default value inside your actions using reset().

You can reset individual, some, or all data properties.

You can also reset all properties EXCEPT the properties you pass.

Locked Properties

Locked properties prevent client-side modifications to sensitive data like user IDs, roles, or permissions. Define a locked variable to protect specific properties from wire:model and other client interactions. CBWIRE throws an exception if locked properties are modified from the client.

Single Property

Multiple Properties

Template Usage

Locked properties can be displayed but not modified through form inputs:

Common Use Cases

  • User Management: Lock userId, role, permissions

  • E-commerce: Lock product IDs, prices, inventory counts

  • Financial: Lock account numbers, balances, transaction IDs

  • Content: Lock author IDs, creation dates, publication status

Locked properties only prevent client-side modifications. Server-side code in your action methods can still modify locked properties when necessary.

Last updated

Was this helpful?