# Defining computed values

Each app can have some specific data transformations needed. Now this can be done via building service that handles this in js, but often times transformation is simple enough that it is easier to define it as a computed value in manifest.

## Usage

In root level of the manifest, inside `config` section, we can define `computed_values` object.

Example:

```js
{
  "config": {
    // ...
    "computed_values": {
      "policy_start_date": {
        "value": {
          "type": "jsonlogic",
          "schema": {
            "var": "active_policy.quote.customer_input.start_date"
          }
        }
      }
    }
  }
}
```

In this example input value `policy_start_date` will be updated whenever value `active_policy.quote.customer_input.start_date` changes with the value it changed to.

### update\_when\_changes

There are some cases where we don't want to update value when it changes. In those cases we can define dependency logic in `update_when_changes` that will handle change detecton instead of `value`.

Example:

```js
{
  "config": {
    // ...
    "computed_values": {
      "data.agents_count": {
        "value": {
          "type": "jsonlogic",
          "schema": {
            "+": [
              {
                "length": {
                  "var": "input.data.agents"
                }
              },
              {
                "var": "input.data.additional_count"
              }
            ]
          }
        },
        "update_when_changes": {
          "type": "jsonlogic",
          "schema": {
            "var": "input.data.additional_count"
          }
        }
      }
    }
  }
}
```

In this example `data.agents_count` input value will only update when `input.data.additional_count` value changes. This would improve performance if `input.data.agents` is static value and we don't want to listen for changes in there.

### skip\_form

All of the computed values will automatically update `input` and `form` state. By adding `skip_form` property we can set this value to be only sent to `input`.

Example:

```js
{
  "config": {
    // ...
    "computed_values": {
      "hello": {
        "value": {
          "type": "jsonlogic",
          "schema": "Hello world"
        },
        "skip_form": true
      }
    }
  }
}
```

In this example `hello` value will only be set in `input` state and not `form`. Meaning this will not update field values in current screen without `watch_changes` enabled on form.
