@aurigma/ui-framework
Version:
A platform which allows building print product personalization editors based on Aurigma's Customer's Canvas.
145 lines (80 loc) • 3.21 kB
Markdown
# Class: VariableManager
Manages variables in the editor scope.
## Hierarchy
* **VariableManager**
## Implements
* [IVariableManager](../interfaces/ivariablemanager.md)
## Index
### Properties
* [editor](variablemanager.md#editor)
* [variables](variablemanager.md#variables)
### Methods
* [append](variablemanager.md#append)
* [appendExpression](variablemanager.md#appendexpression)
* [calculate](variablemanager.md#calculate)
* [calculateAll](variablemanager.md#calculateall)
* [init](variablemanager.md#init)
## Properties
### editor
• **editor**: *[AuWizard](auwizard.md)*
*Implementation of [IVariableManager](../interfaces/ivariablemanager.md).[editor](../interfaces/ivariablemanager.md#editor)*
A reference to an editor's instance.
___
### variables
• **variables**: *any* = null
*Implementation of [IVariableManager](../interfaces/ivariablemanager.md).[variables](../interfaces/ivariablemanager.md#variables)*
An object containing variables for the editor config.
## Methods
### append
▸ **append**(`name`: string, `value`: any, `updateScope`: boolean): *Promise‹void›*
*Implementation of [IVariableManager](../interfaces/ivariablemanager.md)*
Appends a new variable to the `vars` object or updates an existing variable.
**Parameters:**
Name | Type | Default | Description |
------ | ------ | ------ | ------ |
`name` | string | - | The name of the variable. |
`value` | any | - | The value of the variable. |
`updateScope` | boolean | true | If `true`, runs scope recompilation so that widgets get updated parameters. |
**Returns:** *Promise‹void›*
___
### appendExpression
▸ **appendExpression**(`name`: string, `value`: string): *Promise‹any›*
*Implementation of [IVariableManager](../interfaces/ivariablemanager.md)*
Appends a new expression to the editor's variables or updates an existing variable.
You can use this method when you need to calculate the value of an expression.
**Parameters:**
Name | Type | Description |
------ | ------ | ------ |
`name` | string | The name of the variable. |
`value` | string | The expression of the variable. |
**Returns:** *Promise‹any›*
The calculated value of the expression.
___
### calculate
▸ **calculate**(`name`: string): *any*
*Implementation of [IVariableManager](../interfaces/ivariablemanager.md)*
Gets a variable by its name and calculates its value.
**Parameters:**
Name | Type | Description |
------ | ------ | ------ |
`name` | string | The variable name. |
**Returns:** *any*
The calculated value of the variable.
___
### calculateAll
▸ **calculateAll**(): *object*
*Implementation of [IVariableManager](../interfaces/ivariablemanager.md)*
Calculates all the editor's variables.
**Returns:** *object*
A dictionary of calculated variable values.
* \[ **name**: *string*\]: any
___
### init
▸ **init**(`initialVars`: any): *void*
*Implementation of [IVariableManager](../interfaces/ivariablemanager.md)*
Initializes the variable manager with the defined editor's variables.
**Parameters:**
Name | Type | Description |
------ | ------ | ------ |
`initialVars` | any | The `vars` object defined in the editor's config. |
**Returns:** *void*