# BindingTwoWay

Class · extends [`BindingBase`](https://api.playcanvas.com/pcui/classes/BindingBase.md)

Source: https://github.com/playcanvas/pcui/blob/77ed2b8ba8660c9644049b0d1942652721e7a6c4/src/binding/BindingTwoWay/index.ts#L28

Provides two way data binding between Observers and [IBindable](https://api.playcanvas.com/pcui/interfaces/IBindable.md) elements. This means that
when the value of the Observers changes the IBindable will be updated and vice versa.

## Constructors

### constructor

```ts
new BindingTwoWay(args?: Readonly<BindingTwoWayArgs>)
```

Creates a new BindingTwoWay instance.

**Parameters**

- `args` (`Readonly<`[`BindingTwoWayArgs`](https://api.playcanvas.com/pcui/interfaces/BindingTwoWayArgs.md)`>`, optional, default `{}`): The arguments.

## Accessors

### applyingChange

```ts
get applyingChange(): boolean
set applyingChange(value: boolean)
```

Sets whether the binding is currently applying a change, either to the observers or the element.

### element

```ts
get element(): IBindable<unknown>
set element(value: IBindable<unknown>)
```

Sets the element.

### historyCombine

```ts
get historyCombine(): boolean
set historyCombine(value: boolean)
```

Sets whether to combine history actions when applying changes to observers. This is assuming
a history module is being used.

### historyEnabled

```ts
get historyEnabled(): boolean
set historyEnabled(value: boolean)
```

Sets whether history is enabled for the binding. A valid history object must have been provided first.

### historyPostfix

```ts
get historyPostfix(): string
set historyPostfix(value: string)
```

Sets the string to postfix [historyName](https://api.playcanvas.com/pcui/classes/BindingBase.md#historyname) with.

### historyPrefix

```ts
get historyPrefix(): string
set historyPrefix(value: string)
```

Sets the string to prefix [historyName](https://api.playcanvas.com/pcui/classes/BindingBase.md#historyname) with.

## Methods

### addValue

```ts
addValue(value: unknown): void
```

Adds (inserts) a value to the linked observers at the linked paths.

**Parameters**

- `value` (`unknown`): The value.

### addValues

```ts
addValues(values: unknown[]): void
```

Adds (inserts) multiple values to the linked observers at the linked paths.

**Parameters**

- `values` (`unknown[]`): The values.

### clone

```ts
clone(): BindingTwoWay
```

Clones the binding. To be implemented by derived classes.

**Returns** [`BindingTwoWay`](https://api.playcanvas.com/pcui/classes/BindingTwoWay.md)

### link

```ts
link(observers: Observer | Observer[], paths: string | string[]): void
```

Links the specified observers to the specified paths.

**Parameters**

- `observers` (`Observer | Observer[]`): The observer(s).
- `paths` (`string | string[]`): The path(s). The behavior of the binding depends on how many paths are passed.
  If an equal amount of paths and observers are passed then the binding will map each path to each observer at each index.
  If more observers than paths are passed then the path at index 0 will be used for all observers.
  If one observer and multiple paths are passed then all of the paths will be used for the observer (e.g. for curves).

### removeValue

```ts
removeValue(value: unknown): void
```

Removes a value from the linked observers at the linked paths.

**Parameters**

- `value` (`unknown`): The value.

### removeValues

```ts
removeValues(values: unknown[]): void
```

Removes multiple values from the linked observers from the linked paths.

**Parameters**

- `values` (`unknown[]`): The values.

### setValue

```ts
setValue(value: unknown): void
```

Sets a value to the linked observers at the linked paths.

**Parameters**

- `value` (`unknown`): The value

### setValues

```ts
setValues(values: unknown[]): void
```

Sets an array of values to the linked observers at the linked paths.

**Parameters**

- `values` (`unknown[]`): The values.

### unlink

```ts
unlink(): void
```

Unlinks the observers and paths.

## Inherited from [BindingBase](https://api.playcanvas.com/pcui/classes/BindingBase.md)

- `get historyName(): string` · `set historyName(value: string)`
- `get linked(): boolean`
- `get observers(): Observer[]`
- `get paths(): string[]`
