> For the complete documentation index, see [llms.txt](https://wirebox.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wirebox.ortusbooks.com/advanced-topics/property-observers.md).

# Property Observers

Observe any property and react!

WireBox supports the concepts of class property observers. Meaning that you can define a function that will be called for you when the `setter` for that property has been called and thus observe the property changes within a class.

You will accomplish this by tagging a property with an annotation called `observed` and created a function called: `{propertyName}Observer` by convention. This function will receive three arguments:

* `newValue` : The value that will be set into the property
* `oldValue` : The old value of the property, including `null`
* `property` : The name of the property

{% tabs %}
{% tab title="BoxLang" %}

```js
class{

	property name="data" observed;

	/**
	 * Observer for data changes.  Anytime data is set, it will be called
   	 *
	 * @new The new value
	 * @old The old value
	 * @property The name of the property observed
	 */
	function dataObserver( newValue, oldValue, property ){
		// Execute after data is set
	}

}
```

{% endtab %}

{% tab title="CFML" %}

```cfscript
component{

	property name="data" observed;

	/**
	 * Observer for data changes.  Anytime data is set, it will be called
   	 *
	 * @new The new value
	 * @old The old value
	 * @property The name of the property observed
	 */
	function dataObserver( newValue, oldValue, property ){
		// Execute after data is set
	}

}
```

{% endtab %}
{% endtabs %}

If you don’t like the convention and want to name the function as you see fit, then you can place the value of the `observed` annotation as the name of the function to call.

{% tabs %}
{% tab title="BoxLang" %}

```js

class{

	property name="data" observed="myObserver";

	/**
	 * Observer for data changes.  Anytime data is set, it will be called
  	 *
	 * @new The new value
	 * @old The old value
	 * @property The name of the property observed
	 */
	function myObserver( newValue, oldValue, property ){
		// Execute after data is set
	}

}
```

{% endtab %}

{% tab title="CFML" %}

```cfscript

component{

	property name="data" observed="myObserver";

	/**
	 * Observer for data changes.  Anytime data is set, it will be called
  	 *
	 * @new The new value
	 * @old The old value
	 * @property The name of the property observed
	 */
	function myObserver( newValue, oldValue, property ){
		// Execute after data is set
	}

}
```

{% endtab %}
{% endtabs %}

Please note that the observer will be called **AFTER** the property has been set. That's it, enjoy!


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://wirebox.ortusbooks.com/advanced-topics/property-observers.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
