# EditingView

class

Editor's view controller class. Its main responsibility is DOM - View management for editing purposes, to provide abstraction over the DOM structure and events and hide all browsers quirks.

View controller renders view document to DOM whenever view structure changes. To determine when view can be rendered, all changes need to be done using the [`change`](#function-change) method, using [`ViewDowncastWriter`](module_engine_view_downcastwriter-ViewDowncastWriter.md):

```typescript
view.change( writer => {
	writer.insert( position, writer.createText( 'foo' ) );
} );
```

View controller also register [observers](module_engine_view_observer_observer-Observer.md) which observes changes on DOM and fire events on the [Document](module_engine_view_document-ViewDocument.md). Note that the following observers are added by the class constructor and are always available:

* [`SelectionObserver`](module_engine_view_observer_selectionobserver-SelectionObserver.md),
* [`FocusObserver`](module_engine_view_observer_focusobserver-FocusObserver.md),
* [`KeyObserver`](module_engine_view_observer_keyobserver-KeyObserver.md),
* [`FakeSelectionObserver`](module_engine_view_observer_fakeselectionobserver-FakeSelectionObserver.md).
* [`CompositionObserver`](module_engine_view_observer_compositionobserver-CompositionObserver.md).
* [`InputObserver`](module_engine_view_observer_inputobserver-InputObserver.md).
* [`ArrowKeysObserver`](module_engine_view_observer_arrowkeysobserver-ArrowKeysObserver.md).
* [`TabObserver`](module_engine_view_observer_tabobserver-TabObserver.md).

This class also [binds the DOM and the view elements](#function-attachDomRoot).

If you do not need full a DOM - view management, and only want to transform a tree of view elements to a tree of DOM elements you do not need this controller. You can use the [ViewDomConverter](module_engine_view_domconverter-ViewDomConverter.md) instead.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L94)

<a id="properties">

## Properties

<a id="member-document">

### `document: ViewDocument` _(readonly)_

Instance of the [`ViewDocument`](module_engine_view_document-ViewDocument.md) associated with this view controller.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L98)

<a id="member-domConverter">

### `domConverter: ViewDomConverter` _(readonly)_

Instance of the [domConverter](module_engine_view_domconverter-ViewDomConverter.md) used by [renderer](#member-_renderer) and [observers](module_engine_view_observer_observer-Observer.md).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L105)

<a id="member-domRoots">

### `domRoots: Map<string, HTMLElement>` _(readonly)_

Roots of the DOM tree. Map on the `HTMLElement`s with roots names as keys.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L110)

<a id="member-hasDomSelection">

### `hasDomSelection: boolean` _(readonly)_

Informs whether the DOM selection is inside any of the DOM roots managed by the view.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L126)

<a id="member-isRenderingInProgress">

### `isRenderingInProgress: boolean` _(readonly)_

Used to prevent calling [`forceRender`](#function-forceRender) and [`change`](#function-change) during rendering view to the DOM.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L118)

<a id="member-_hasChangedSinceTheLastRendering">

### `_hasChangedSinceTheLastRendering: boolean` _(private)_

Internal flag that disables rendering when there are no changes since the last rendering. It stores information about changed selection and changed elements from attached document roots.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L170)

<a id="member-_initialDomRootAttributes">

### `_initialDomRootAttributes: WeakMap<HTMLElement, Record<string, string>>` _(private)_

A DOM root attributes cache. It saves the initial values of DOM root attributes before the DOM element is [attached](#function-attachDomRoot) to the view so later on, when the view is destroyed ([`detachDomRoot`](#function-detachDomRoot)), they can be easily restored. This way, the DOM element can go back to the (clean) state as if the editing view never used it.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L139)

<a id="member-_observers">

### `_observers: Map<ObserverConstructor, Observer>` _(private)_

Map of registered [observers](module_engine_view_observer_observer-Observer.md).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L144)

<a id="member-_ongoingChange">

### `_ongoingChange: boolean` _(private)_

Is set to `true` when [view changes](#function-change) are currently in progress.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L154)

<a id="member-_postFixersInProgress">

### `_postFixersInProgress: boolean` _(private)_

Used to prevent calling [`forceRender`](#function-forceRender) and [`change`](#function-change) during rendering view to the DOM.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L159)

<a id="member-_renderer">

### `_renderer: ViewRenderer` _(private)_

Instance of the [renderer](module_engine_view_renderer-ViewRenderer.md).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L131)

<a id="member-_renderingDisabled">

### `_renderingDisabled: boolean` _(private)_

Internal flag to temporary disable rendering. See the usage in the [`_disableRendering`](#function-_disableRendering).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L164)

<a id="member-_writer">

### `_writer: ViewDowncastWriter` _(private)_

ViewDowncastWriter instance used in [change method](#function-change) callbacks.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L149)

<a id="methods">

## Methods

<a id="function-constructor">

### `constructor( stylesProcessor )`

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L175)

#### Parameters

* `stylesProcessor: StylesProcessor`

  The styles processor instance.

<a id="function-addObserver">

### `addObserver( ObserverConstructor ) → Observer`

Creates observer of the given type if not yet created, [enables](module_engine_view_observer_observer-Observer.md#function-enable) it and [attaches](module_engine_view_observer_observer-Observer.md#function-observe) to all existing and future [DOM roots](#member-domRoots).

Note: Observers are recognized by their constructor (classes). A single observer will be instantiated and used only when registered for the first time. This means that features and other components can register a single observer multiple times without caring whether it has been already added or not.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L392)

#### Parameters

* `ObserverConstructor: ObserverConstructor`

  The constructor of an observer to add. Should create an instance inheriting from [`Observer`](module_engine_view_observer_observer-Observer.md).

#### Returns

* `Observer`

  Added observer instance.

<a id="function-attachDomRoot">

### `attachDomRoot( domRoot, name ) → void`

Attaches a DOM root element to the view element and enable all observers on that element. Also [mark element](module_engine_view_renderer-ViewRenderer.md#function-markToSync) to be synchronized with the view what means that all child nodes will be removed and replaced with content of the view root.

This method also will change view element name as the same as tag name of given dom root. Name is always transformed to lower case.

**Note:** Use [`detachDomRoot()`](#function-detachDomRoot) to revert this action.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L270)

#### Parameters

* `domRoot: HTMLElement`

  DOM root element.

* `name: string`

  Name of the root.

  Defaults to `'main'`

#### Returns

* `void`

<a id="function-bind:MANY_BIND">

### `bind( bindProperties ) → ObservableMultiBindChain` _(inherited)_

Binds [observable properties](#function-set:KEY_VALUE) to other objects implementing the [`Observable`](module_utils_observablemixin-Observable.md) interface.

Read more in the [dedicated](../framework/deep-dive/observables.md#property-bindings) guide covering the topic of property bindings with some additional examples.

Consider two objects: a `button` and an associated `command` (both `Observable`).

A simple property binding could be as follows:

```typescript
button.bind( 'isEnabled' ).to( command, 'isEnabled' );
```

or even shorter:

```typescript
button.bind( 'isEnabled' ).to( command );
```

which works in the following way:

* `button.isEnabled` **instantly equals** `command.isEnabled`,
* whenever `command.isEnabled` changes, `button.isEnabled` will immediately reflect its value.

**Note**: To release the binding, use [`unbind`](module_utils_observablemixin-Observable.md#function-unbind).

You can also "rename" the property in the binding by specifying the new name in the `to()` chain:

```typescript
button.bind( 'isEnabled' ).to( command, 'isWorking' );
```

It is possible to bind more than one property at a time to shorten the code:

```typescript
button.bind( 'isEnabled', 'value' ).to( command );
```

which corresponds to:

```typescript
button.bind( 'isEnabled' ).to( command );
button.bind( 'value' ).to( command );
```

The binding can include more than one observable, combining multiple data sources in a custom callback:

```typescript
button.bind( 'isEnabled' ).to( command, 'isEnabled', ui, 'isVisible',
	( isCommandEnabled, isUIVisible ) => isCommandEnabled && isUIVisible );
```

Using a custom callback allows processing the value before passing it to the target property:

```typescript
button.bind( 'isEnabled' ).to( command, 'value', value => value === 'heading1' );
```

It is also possible to bind to the same property in an array of observables. To bind a `button` to multiple commands (also `Observables`) so that each and every one of them must be enabled for the button to become enabled, use the following code:

```typescript
button.bind( 'isEnabled' ).toMany( [ commandA, commandB, commandC ], 'isEnabled',
	( isAEnabled, isBEnabled, isCEnabled ) => isAEnabled && isBEnabled && isCEnabled );
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/observablemixin.ts#L1074)

#### Parameters

* `bindProperties: Array<'off' | 'set' | 'bind' | 'unbind' | 'decorate' | 'stopListening' | 'on' | 'once' | 'listenTo' | 'fire' | 'delegate' | 'stopDelegating' | 'change' | 'focus' | 'document' | 'destroy' | 'createPositionAt' | 'createPositionAfter' | 'createPositionBefore' | 'createRange' | 'createRangeIn' | 'createRangeOn' | 'createSelection' | 'domConverter' | 'domRoots' | 'isRenderingInProgress' | 'hasDomSelection' | 'attachDomRoot' | 'detachDomRoot' | 'getDomRoot' | 'addObserver' | 'getObserver' | 'disableObservers' | 'enableObservers' | 'scrollToTheSelection' | 'forceRender' | '_disableRendering'>`

  Observable properties that will be bound to other observable(s).

#### Returns

* `ObservableMultiBindChain`

  The bind chain with the `to()` and `toMany()` methods.

<a id="function-bind:DUAL_BIND">

### `bind( bindProperty1, bindProperty2 ) → ObservableDualBindChain<K1, EditingView[ K1 ], K2, EditingView[ K2 ]>` _(inherited)_

Binds [observable properties](#function-set:KEY_VALUE) to other objects implementing the [`Observable`](module_utils_observablemixin-Observable.md) interface.

Read more in the [dedicated](../framework/deep-dive/observables.md#property-bindings) guide covering the topic of property bindings with some additional examples.

Consider two objects: a `button` and an associated `command` (both `Observable`).

A simple property binding could be as follows:

```typescript
button.bind( 'isEnabled' ).to( command, 'isEnabled' );
```

or even shorter:

```typescript
button.bind( 'isEnabled' ).to( command );
```

which works in the following way:

* `button.isEnabled` **instantly equals** `command.isEnabled`,
* whenever `command.isEnabled` changes, `button.isEnabled` will immediately reflect its value.

**Note**: To release the binding, use [`unbind`](module_utils_observablemixin-Observable.md#function-unbind).

You can also "rename" the property in the binding by specifying the new name in the `to()` chain:

```typescript
button.bind( 'isEnabled' ).to( command, 'isWorking' );
```

It is possible to bind more than one property at a time to shorten the code:

```typescript
button.bind( 'isEnabled', 'value' ).to( command );
```

which corresponds to:

```typescript
button.bind( 'isEnabled' ).to( command );
button.bind( 'value' ).to( command );
```

The binding can include more than one observable, combining multiple data sources in a custom callback:

```typescript
button.bind( 'isEnabled' ).to( command, 'isEnabled', ui, 'isVisible',
	( isCommandEnabled, isUIVisible ) => isCommandEnabled && isUIVisible );
```

Using a custom callback allows processing the value before passing it to the target property:

```typescript
button.bind( 'isEnabled' ).to( command, 'value', value => value === 'heading1' );
```

It is also possible to bind to the same property in an array of observables. To bind a `button` to multiple commands (also `Observables`) so that each and every one of them must be enabled for the button to become enabled, use the following code:

```typescript
button.bind( 'isEnabled' ).toMany( [ commandA, commandB, commandC ], 'isEnabled',
	( isAEnabled, isBEnabled, isCEnabled ) => isAEnabled && isBEnabled && isCEnabled );
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/observablemixin.ts#L996)

#### Type parameters

* * `K1`
  * `K2`

#### Parameters

* `bindProperty1: K1`

  Observable property that will be bound to other observable(s).

* `bindProperty2: K2`

  Observable property that will be bound to other observable(s).

#### Returns

* `ObservableDualBindChain<K1, EditingView[ K1 ], K2, EditingView[ K2 ]>`

  The bind chain with the `to()` and `toMany()` methods.

<a id="function-bind:SINGLE_BIND">

### `bind( bindProperty ) → ObservableSingleBindChain<K, EditingView[ K ]>` _(inherited)_

Binds [observable properties](#function-set:KEY_VALUE) to other objects implementing the [`Observable`](module_utils_observablemixin-Observable.md) interface.

Read more in the [dedicated](../framework/deep-dive/observables.md#property-bindings) guide covering the topic of property bindings with some additional examples.

Consider two objects: a `button` and an associated `command` (both `Observable`).

A simple property binding could be as follows:

```typescript
button.bind( 'isEnabled' ).to( command, 'isEnabled' );
```

or even shorter:

```typescript
button.bind( 'isEnabled' ).to( command );
```

which works in the following way:

* `button.isEnabled` **instantly equals** `command.isEnabled`,
* whenever `command.isEnabled` changes, `button.isEnabled` will immediately reflect its value.

**Note**: To release the binding, use [`unbind`](module_utils_observablemixin-Observable.md#function-unbind).

You can also "rename" the property in the binding by specifying the new name in the `to()` chain:

```typescript
button.bind( 'isEnabled' ).to( command, 'isWorking' );
```

It is possible to bind more than one property at a time to shorten the code:

```typescript
button.bind( 'isEnabled', 'value' ).to( command );
```

which corresponds to:

```typescript
button.bind( 'isEnabled' ).to( command );
button.bind( 'value' ).to( command );
```

The binding can include more than one observable, combining multiple data sources in a custom callback:

```typescript
button.bind( 'isEnabled' ).to( command, 'isEnabled', ui, 'isVisible',
	( isCommandEnabled, isUIVisible ) => isCommandEnabled && isUIVisible );
```

Using a custom callback allows processing the value before passing it to the target property:

```typescript
button.bind( 'isEnabled' ).to( command, 'value', value => value === 'heading1' );
```

It is also possible to bind to the same property in an array of observables. To bind a `button` to multiple commands (also `Observables`) so that each and every one of them must be enabled for the button to become enabled, use the following code:

```typescript
button.bind( 'isEnabled' ).toMany( [ commandA, commandB, commandC ], 'isEnabled',
	( isAEnabled, isBEnabled, isCEnabled ) => isAEnabled && isBEnabled && isCEnabled );
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/observablemixin.ts#L918)

#### Type parameters

* `K`

#### Parameters

* `bindProperty: K`

  Observable property that will be bound to other observable(s).

#### Returns

* `ObservableSingleBindChain<K, EditingView[ K ]>`

  The bind chain with the `to()` and `toMany()` methods.

<a id="function-change">

### `change( callback ) → TReturn`

The `change()` method is the primary way of changing the view. You should use it to modify any node in the view tree. It makes sure that after all changes are made the view is rendered to the DOM (assuming that the view will be changed inside the callback). It prevents situations when the DOM is updated when the view state is not yet correct. It allows to nest calls one inside another and still performs a single rendering after all those changes are made. It also returns the return value of its callback.

```typescript
const text = view.change( writer => {
	const newText = writer.createText( 'foo' );
	writer.insert( position1, newText );

	view.change( writer => {
		writer.insert( position2, writer.createText( 'bar' ) );
	} );

	writer.remove( range );

	return newText;
} );
```

When the outermost change block is done and rendering to the DOM is over the [`View#render`](#event-render) event is fired.

This method throws a `applying-view-changes-on-rendering` error when the change block is used after rendering to the DOM has started.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L556)

#### Type parameters

* `TReturn`

#### Parameters

* `callback: ( writer: ViewDowncastWriter ) => TReturn`

  Callback function which may modify the view.

#### Returns

* `TReturn`

  Value returned by the callback.

<a id="function-createPositionAfter">

### `createPositionAfter( item ) → ViewPosition`

Creates a new position after given view item.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L659)

#### Parameters

* `item: ViewItem`

  View item after which the position should be located.

#### Returns

* `ViewPosition`

<a id="function-createPositionAt">

### `createPositionAt( itemOrPosition, offset? ) → ViewPosition`

Creates position at the given location. The location can be specified as:

* a [position](module_engine_view_position-ViewPosition.md),
* parent element and offset (offset defaults to `0`),
* parent element and `'end'` (sets position at the end of that element),
* [view item](module_engine_view_item-ViewItem.md) and `'before'` or `'after'` (sets position before or after given view item).

This method is a shortcut to other constructors such as:

* [`createPositionBefore`](#function-createPositionBefore),
* [`createPositionAfter`](#function-createPositionAfter),

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L650)

#### Parameters

* `itemOrPosition: ViewPosition | ViewItem`

* `offset?: ViewPositionOffset`

  Offset or one of the flags. Used only when first parameter is a [view item](module_engine_view_item-ViewItem.md).

#### Returns

* `ViewPosition`

<a id="function-createPositionBefore">

### `createPositionBefore( item ) → ViewPosition`

Creates a new position before given view item.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L668)

#### Parameters

* `item: ViewItem`

  View item before which the position should be located.

#### Returns

* `ViewPosition`

<a id="function-createRange">

### `createRange( start, end? ) → ViewRange`

Creates a range spanning from `start` position to `end` position.

**Note:** This factory method creates it's own [`ViewPosition`](module_engine_view_position-ViewPosition.md) instances basing on passed values.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L680)

#### Parameters

* `start: ViewPosition`

  Start position.

* `end?: ViewPosition | null`

  End position. If not set, range will be collapsed at `start` position.

#### Returns

* `ViewRange`

<a id="function-createRangeIn">

### `createRangeIn( element ) → ViewRange`

Creates a range inside an [element](module_engine_view_element-ViewElement.md) which starts before the first child of that element and ends after the last child of that element.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L697)

#### Parameters

* `element: ViewElement | ViewDocumentFragment`

  Element which is a parent for the range.

#### Returns

* `ViewRange`

<a id="function-createRangeOn">

### `createRangeOn( item ) → ViewRange`

Creates a range that starts before given [view item](module_engine_view_item-ViewItem.md) and ends after it.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L687)

#### Parameters

* `item: ViewItem`

#### Returns

* `ViewRange`

<a id="function-createSelection:SELECTABLE">

### `createSelection( selectable?, options? ) → ViewSelection`

Creates new [`ViewSelection`](module_engine_view_selection-ViewSelection.md) instance.

```typescript
// Creates empty selection without ranges.
const selection = view.createSelection();

// Creates selection at the given range.
const range = view.createRange( start, end );
const selection = view.createSelection( range );

// Creates selection at the given ranges
const ranges = [ view.createRange( start1, end2 ), view.createRange( star2, end2 ) ];
const selection = view.createSelection( ranges );

// Creates selection from the other selection.
const otherSelection = view.createSelection();
const selection = view.createSelection( otherSelection );

// Creates selection from the document selection.
const selection = view.createSelection( editor.editing.view.document.selection );

// Creates selection at the given position.
const position = view.createPositionFromPath( root, path );
const selection = view.createSelection( position );
```

`Selection`'s factory method allow passing additional options (`backward`, `fake` and `label`) as the last argument.

```typescript
// Creates backward selection.
const selection = view.createSelection( range, { backward: true } );
```

Fake selection does not render as browser native selection over selected elements and is hidden to the user. This way, no native selection UI artifacts are displayed to the user and selection over elements can be represented in other way, for example by applying proper CSS class.

Additionally fake's selection label can be provided. It will be used to describe fake selection in DOM (and be properly handled by screen readers).

```typescript
// Creates fake selection with label.
const selection = view.createSelection( range, { fake: true, label: 'foo' } );
```

See also: [`createSelection( node, placeOrOffset, options )`](#function-createSelection:NODE_OFFSET).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L793)

#### Parameters

* `selectable?: ViewPosition | ViewRange | ViewSelection | ViewDocumentSelection | Iterable<ViewRange, any, any> | null`
* `options?: ViewSelectionOptions`

#### Returns

* `ViewSelection`

<a id="function-createSelection:NODE_OFFSET">

### `createSelection( selectable, placeOrOffset, options? ) → ViewSelection`

Creates new [`ViewSelection`](module_engine_view_selection-ViewSelection.md) instance.

```typescript
// Creates collapsed selection at the position of given item and offset.
const paragraph = view.createContainerElement( 'paragraph' );
const selection = view.createSelection( paragraph, offset );

// Creates a range inside an element which starts before the
// first child of that element and ends after the last child of that element.
const selection = view.createSelection( paragraph, 'in' );

// Creates a range on an item which starts before the item and ends
// just after the item.
const selection = view.createSelection( paragraph, 'on' );
```

`Selection`'s factory method allow passing additional options (`backward`, `fake` and `label`) as the last argument.

```typescript
// Creates backward selection.
const selection = view.createSelection( paragraph, 'in', { backward: true } );
```

Fake selection does not render as browser native selection over selected elements and is hidden to the user. This way, no native selection UI artifacts are displayed to the user and selection over elements can be represented in other way, for example by applying proper CSS class.

Additionally fake's selection label can be provided. It will be used to describe fake selection in DOM (and be properly handled by screen readers).

```typescript
// Creates fake selection with label.
const selection = view.createSelection( element, 'in', { fake: true, label: 'foo' } );
```

See also: [`createSelection( selectable, options )`](#function-createSelection:SELECTABLE).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L741)

#### Parameters

* `selectable: ViewNode`
* `placeOrOffset: ViewPlaceOrOffset`
* `options?: ViewSelectionOptions`

#### Returns

* `ViewSelection`

<a id="function-decorate">

### `decorate( methodName ) → void` _(inherited)_

Turns the given methods of this object into event-based ones. This means that the new method will fire an event (named after the method) and the original action will be plugged as a listener to that event.

Read more in the [dedicated](../framework/deep-dive/observables.md#decorating-object-methods) guide covering the topic of decorating methods with some additional examples.

Decorating the method does not change its behavior (it only adds an event), but it allows to modify it later on by listening to the method's event.

For example, to cancel the method execution the event can be [stopped](module_utils_eventinfo-EventInfo.md#member-stop):

```typescript
class Foo extends ObservableMixin() {
	constructor() {
		super();
		this.decorate( 'method' );
	}

	method() {
		console.log( 'called!' );
	}
}

const foo = new Foo();
foo.on( 'method', ( evt ) => {
	evt.stop();
}, { priority: 'high' } );

foo.method(); // Nothing is logged.
```

**Note**: The high [priority](module_utils_priorities-PriorityString.md) listener has been used to execute this particular callback before the one which calls the original method (which uses the "normal" priority).

It is also possible to change the returned value:

```typescript
foo.on( 'method', ( evt ) => {
	evt.return = 'Foo!';
} );

foo.method(); // -> 'Foo'
```

Finally, it is possible to access and modify the arguments the method is called with:

```typescript
method( a, b ) {
	console.log( `${ a }, ${ b }`  );
}

// ...

foo.on( 'method', ( evt, args ) => {
	args[ 0 ] = 3;

	console.log( args[ 1 ] ); // -> 2
}, { priority: 'high' } );

foo.method( 1, 2 ); // -> '3, 2'
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/observablemixin.ts#L1159)

#### Parameters

* `methodName: 'off' | 'set' | 'bind' | 'unbind' | 'decorate' | 'stopListening' | 'on' | 'once' | 'listenTo' | 'fire' | 'delegate' | 'stopDelegating' | 'change' | 'focus' | 'document' | 'destroy' | 'createPositionAt' | 'createPositionAfter' | 'createPositionBefore' | 'createRange' | 'createRangeIn' | 'createRangeOn' | 'createSelection' | 'domConverter' | 'domRoots' | 'isRenderingInProgress' | 'hasDomSelection' | 'attachDomRoot' | 'detachDomRoot' | 'getDomRoot' | 'addObserver' | 'getObserver' | 'disableObservers' | 'enableObservers' | 'scrollToTheSelection' | 'forceRender' | '_disableRendering'`

  Name of the method to decorate.

#### Returns

* `void`

<a id="function-delegate">

### `delegate( events ) → EmitterMixinDelegateChain` _(inherited)_

Delegates selected events to another [`Emitter`](module_utils_emittermixin-Emitter.md). For instance:

```typescript
emitterA.delegate( 'eventX' ).to( emitterB );
emitterA.delegate( 'eventX', 'eventY' ).to( emitterC );
```

then `eventX` is delegated (fired by) `emitterB` and `emitterC` along with `data`:

```typescript
emitterA.fire( 'eventX', data );
```

and `eventY` is delegated (fired by) `emitterC` along with `data`:

```typescript
emitterA.fire( 'eventY', data );
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/emittermixin.ts#L539)

#### Parameters

* `events: Array<string>`

  Event names that will be delegated to another emitter.

#### Returns

* `EmitterMixinDelegateChain`

<a id="function-destroy">

### `destroy() → void`

Destroys this instance. Makes sure that all observers are destroyed and listeners removed.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L625)

#### Returns

* `void`

<a id="function-detachDomRoot">

### `detachDomRoot( name ) → void`

Detaches a DOM root element from the view element and restores its attributes to the state before [`attachDomRoot()`](#function-attachDomRoot).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L347)

#### Parameters

* `name: string`

  Name of the root to detach.

#### Returns

* `void`

<a id="function-disableObservers">

### `disableObservers() → void`

Disables all added observers.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L428)

#### Returns

* `void`

<a id="function-enableObservers">

### `enableObservers() → void`

Enables all added observers.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L437)

#### Returns

* `void`

<a id="function-fire">

### `fire( eventOrInfo, args ) → GetEventInfo<TEvent>[ 'return' ]` _(inherited)_

Fires an event, executing all callbacks registered for it.

The first parameter passed to callbacks is an [`EventInfo`](module_utils_eventinfo-EventInfo.md) object, followed by the optional `args` provided in the `fire()` method call.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/emittermixin.ts#L512)

#### Type parameters

* `TEvent: extends BaseEvent`

  The type describing the event. See [`BaseEvent`](module_utils_emittermixin-BaseEvent.md).

#### Parameters

* `eventOrInfo: GetNameOrEventInfo<TEvent>`

  The name of the event or `EventInfo` object if event is delegated.

* `args: TEvent[ 'args' ]`

  Additional arguments to be passed to the callbacks.

#### Returns

* `GetEventInfo<TEvent>[ 'return' ]`

  By default the method returns `undefined`. However, the return value can be changed by listeners through modification of the [`evt.return`](module_utils_eventinfo-EventInfo.md#member-return)'s property (the event info is the first param of every callback).

<a id="function-focus">

### `focus() → void`

It will focus DOM element representing [ViewEditableElement](module_engine_view_editableelement-ViewEditableElement.md) that is currently having selection inside.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L508)

#### Returns

* `void`

<a id="function-forceRender">

### `forceRender() → void`

Forces rendering [view document](module_engine_view_document-ViewDocument.md) to DOM. If any view changes are currently in progress, rendering will start after all [change blocks](#function-change) are processed.

Note that this method is dedicated for special cases. All view changes should be wrapped in the [`change`](#function-change) block and the view will automatically check whether it needs to render DOM or not.

Throws [CKEditorError](module_utils_ckeditorerror-CKEditorError.md) `applying-view-changes-on-rendering` when trying to re-render when rendering to DOM has already started.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L616)

#### Returns

* `void`

<a id="function-getDomRoot">

### `getDomRoot( name ) → HTMLElement | undefined`

Gets DOM root element.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L375)

#### Parameters

* `name: string`

  Name of the root.

  Defaults to `'main'`

#### Returns

* `HTMLElement | undefined`

  DOM root element instance.

<a id="function-getObserver">

### `getObserver( ObserverConstructor ) → T extends AlwaysRegisteredViewObservers ? InstanceType<T> : InstanceType<T> | undefined`

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L412)

#### Type parameters

* `T: extends ObserverConstructor`

#### Parameters

* `ObserverConstructor: T`

  The constructor of an observer to get.

#### Returns

* `T extends AlwaysRegisteredViewObservers ? InstanceType<T> : InstanceType<T> | undefined`

  Observer instance or undefined.

<a id="function-listenTo:BASE_EMITTER">

### `listenTo( emitter, event, callback, options? ) → void` _(inherited)_

Registers a callback function to be executed when an event is fired in a specific (emitter) object.

Events can be grouped in namespaces using `:`. When namespaced event is fired, it additionally fires all callbacks for that namespace.

```typescript
// myEmitter.on( ... ) is a shorthand for myEmitter.listenTo( myEmitter, ... ).
myEmitter.on( 'myGroup', genericCallback );
myEmitter.on( 'myGroup:myEvent', specificCallback );

// genericCallback is fired.
myEmitter.fire( 'myGroup' );
// both genericCallback and specificCallback are fired.
myEmitter.fire( 'myGroup:myEvent' );
// genericCallback is fired even though there are no callbacks for "foo".
myEmitter.fire( 'myGroup:foo' );
```

An event callback can [stop the event](module_utils_eventinfo-EventInfo.md#member-stop) and set the [return value](module_utils_eventinfo-EventInfo.md#member-return) of the [`fire`](#function-fire) method.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/emittermixin.ts#L475)

#### Type parameters

* `TEvent: extends BaseEvent`

  The type describing the event. See [`BaseEvent`](module_utils_emittermixin-BaseEvent.md).

#### Parameters

* `emitter: Emitter`

  The object that fires the event.

* `event: TEvent[ 'name' ]`

  The name of the event.

* `callback: GetCallback<TEvent>`

  The function to be called on event.

* `options?: GetCallbackOptions<TEvent>`

  Additional options.

#### Returns

* `void`

<a id="function-off">

### `off( event, callback ) → void` _(inherited)_

Stops executing the callback on the given event. Shorthand for [`this.stopListening( this, event, callback )`](#function-stopListening:BASE_STOP).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/emittermixin.ts#L444)

#### Parameters

* `event: string`

  The name of the event.

* `callback: Function`

  The function to stop being called.

#### Returns

* `void`

<a id="function-on">

### `on( event, callback, options? ) → void` _(inherited)_

Registers a callback function to be executed when an event is fired.

Shorthand for [`this.listenTo( this, event, callback, options )`](#function-listenTo:BASE_EMITTER) (it makes the emitter listen on itself).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/emittermixin.ts#L416)

#### Type parameters

* `TEvent: extends BaseEvent`

  The type descibing the event. See [`BaseEvent`](module_utils_emittermixin-BaseEvent.md).

#### Parameters

* `event: TEvent[ 'name' ]`

  The name of the event.

* `callback: GetCallback<TEvent>`

  The function to be called on event.

* `options?: GetCallbackOptions<TEvent>`

  Additional options.

#### Returns

* `void`

<a id="function-once">

### `once( event, callback, options? ) → void` _(inherited)_

Registers a callback function to be executed on the next time the event is fired only. This is similar to calling [`on`](#function-on) followed by [`off`](#function-off) in the callback.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/emittermixin.ts#L431)

#### Type parameters

* `TEvent: extends BaseEvent`

  The type descibing the event. See [`BaseEvent`](module_utils_emittermixin-BaseEvent.md).

#### Parameters

* `event: TEvent[ 'name' ]`

  The name of the event.

* `callback: GetCallback<TEvent>`

  The function to be called on event.

* `options?: GetCallbackOptions<TEvent>`

  Additional options.

#### Returns

* `void`

<a id="function-scrollToTheSelection">

### `scrollToTheSelection( options = { options.alignToTop?, options.ancestorOffset?, options.forceScroll?, options.viewportOffset? } ) → void`

Scrolls the page viewport and [`domRoots`](#member-domRoots) with their ancestors to reveal the caret, **if not already visible to the user**.

**Note**: Calling this method fires the [`ViewScrollToTheSelectionEvent`](module_engine_view_view-ViewScrollToTheSelectionEvent.md) event that allows custom behaviors.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L462)

#### Type parameters

* * `T: extends boolean`
  * `U: extends true`

#### Parameters

* `options: object`

  Additional configuration of the scrolling behavior.

  Properties

  * `options.alignToTop?: T`

    When set `true`, the DOM selection will be aligned to the top of the viewport if not already visible (see `forceScroll` to learn more).

  * `options.ancestorOffset?: number`

    A distance between the DOM selection and scrollable DOM root ancestor(s) to be maintained while scrolling to the selection (default is 20px). Setting this value to `0` will reveal the selection precisely at the scrollable ancestor(s) boundary.

    Defaults to `20`

  * `options.forceScroll?: U`

    When set `true`, the DOM selection will be aligned to the top of the viewport and scrollable ancestors whether it is already visible or not. This option will only work when `alignToTop` is `true`.

  * `options.viewportOffset?: number | object`

    A distance between the DOM selection and the viewport boundary to be maintained while scrolling to the selection (default is 20px). Setting this value to `0` will reveal the selection precisely at the viewport boundary.

    Defaults to `20`

  Defaults to `{}`

#### Returns

* `void`

<a id="function-set:OBJECT">

### `set( values ) → void` _(inherited)_

Creates and sets the value of an observable properties of this object. Such a property becomes a part of the state and is observable.

It accepts a single object literal containing key/value pairs with properties to be set.

This method throws the `observable-set-cannot-override` error if the observable instance already has a property with the given property name. This prevents from mistakenly overriding existing properties and methods, but means that `foo.set( 'bar', 1 )` may be slightly slower than `foo.bar = 1`.

In TypeScript, those properties should be declared in class using `declare` keyword. In example:

```typescript
public declare myProp1: number;
public declare myProp2: string;

constructor() {
	this.set( {
		'myProp1: 2,
		'myProp2: 'foo'
	} );
}
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/observablemixin.ts#L843)

#### Parameters

* `values: object & object`

  An object with `name=>value` pairs.

#### Returns

* `void`

<a id="function-set:KEY_VALUE">

### `set( name, value ) → void` _(inherited)_

Creates and sets the value of an observable property of this object. Such a property becomes a part of the state and is observable.

This method throws the `observable-set-cannot-override` error if the observable instance already has a property with the given property name. This prevents from mistakenly overriding existing properties and methods, but means that `foo.set( 'bar', 1 )` may be slightly slower than `foo.bar = 1`.

In TypeScript, those properties should be declared in class using `declare` keyword. In example:

```typescript
public declare myProp: number;

constructor() {
	this.set( 'myProp', 2 );
}
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/observablemixin.ts#L815)

#### Type parameters

* `K`

#### Parameters

* `name: K`

  The property's name.

* `value: EditingView[ K ]`

  The property's value.

#### Returns

* `void`

<a id="function-stopDelegating">

### `stopDelegating( event?, emitter? ) → void` _(inherited)_

Stops delegating events. It can be used at different levels:

* To stop delegating all events.
* To stop delegating a specific event to all emitters.
* To stop delegating a specific event to a specific emitter.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/emittermixin.ts#L552)

#### Parameters

* `event?: string`

  The name of the event to stop delegating. If omitted, stops it all delegations.

* `emitter?: Emitter`

  (requires `event`) The object to stop delegating a particular event to. If omitted, stops delegation of `event` to all emitters.

#### Returns

* `void`

<a id="function-stopListening:BASE_STOP">

### `stopListening( emitter?, event?, callback? ) → void` _(inherited)_

Stops listening for events. It can be used at different levels:

* To stop listening to a specific callback.
* To stop listening to a specific event.
* To stop listening to all events fired by a specific object.
* To stop listening to all events fired by all objects.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/emittermixin.ts#L497)

#### Parameters

* `emitter?: Emitter`

  The object to stop listening to. If omitted, stops it for all objects.

* `event?: string`

  (Requires the `emitter`) The name of the event to stop listening to. If omitted, stops it for all events from `emitter`.

* `callback?: Function`

  (Requires the `event`) The function to be removed from the call list for the given `event`.

#### Returns

* `void`

<a id="function-unbind">

### `unbind( unbindProperties ) → void` _(inherited)_

Removes the binding created with [`bind`](#function-bind:SINGLE_BIND).

```typescript
// Removes the binding for the 'a' property.
A.unbind( 'a' );

// Removes bindings for all properties.
A.unbind();
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/observablemixin.ts#L1090)

#### Parameters

* `unbindProperties: Array<'off' | 'set' | 'bind' | 'unbind' | 'decorate' | 'stopListening' | 'on' | 'once' | 'listenTo' | 'fire' | 'delegate' | 'stopDelegating' | 'change' | 'focus' | 'document' | 'destroy' | 'createPositionAt' | 'createPositionAfter' | 'createPositionBefore' | 'createRange' | 'createRangeIn' | 'createRangeOn' | 'createSelection' | 'domConverter' | 'domRoots' | 'isRenderingInProgress' | 'hasDomSelection' | 'attachDomRoot' | 'detachDomRoot' | 'getDomRoot' | 'addObserver' | 'getObserver' | 'disableObservers' | 'enableObservers' | 'scrollToTheSelection' | 'forceRender' | '_disableRendering'>`

  Observable properties to be unbound. All the bindings will be released if no properties are provided.

#### Returns

* `void`

<a id="function-_disableRendering">

### `_disableRendering( flag ) → void` _(internal)_

Disables or enables rendering. If the flag is set to `true` then the rendering will be disabled. If the flag is set to `false` and if there was some change in the meantime, then the rendering action will be performed.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L806)

#### Parameters

* `flag: boolean`

  A flag indicates whether the rendering should be disabled.

#### Returns

* `void`

<a id="function-_render">

### `_render() → void` _(private)_

Renders all changes. In order to avoid triggering the observers (e.g. selection) all observers are disabled before rendering and re-enabled after that.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L819)

#### Returns

* `void`

<a id="events">

## Events

<a id="event-change:hasDomSelection">

### `change:hasDomSelection( eventInfo, name, value, oldValue )`

Fired when the `hasDomSelection` property changed value.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L126)

#### Parameters

* `eventInfo: EventInfo`

  An object containing information about the fired event.

* `name: string`

  Name of the changed property (`hasDomSelection`).

* `value: boolean`

  New value of the `hasDomSelection` property with given key or `null`, if operation should remove property.

* `oldValue: boolean`

  Old value of the `hasDomSelection` property with given key or `null`, if property was not set before.

<a id="event-change:isRenderingInProgress">

### `change:isRenderingInProgress( eventInfo, name, value, oldValue )`

Fired when the `isRenderingInProgress` property changed value.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L118)

#### Parameters

* `eventInfo: EventInfo`

  An object containing information about the fired event.

* `name: string`

  Name of the changed property (`isRenderingInProgress`).

* `value: boolean`

  New value of the `isRenderingInProgress` property with given key or `null`, if operation should remove property.

* `oldValue: boolean`

  Old value of the `isRenderingInProgress` property with given key or `null`, if property was not set before.

<a id="event-change:%7Bproperty%7D">

### `change:{property}( eventInfo, name, value, oldValue )` _(inherited)_

Fired when a property changed value.

```typescript
observable.set( 'prop', 1 );

observable.on<ObservableChangeEvent<number>>( 'change:prop', ( evt, propertyName, newValue, oldValue ) => {
	console.log( `${ propertyName } has changed from ${ oldValue } to ${ newValue }` );
} );

observable.prop = 2; // -> 'prop has changed from 1 to 2'
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/observablemixin.ts#L1190)

#### Parameters

* `eventInfo: EventInfo`

  An object containing information about the fired event.

* `name: string`

  The property name.

* `value: TValue`

  The new property value.

* `oldValue: TValue`

  The previous property value.

<a id="event-render">

### `render( eventInfo )`

Fired after a topmost [change block](#function-change) and all [post-fixers](module_engine_view_document-ViewDocument.md#function-registerPostFixer) are executed.

Actual rendering is performed as a first listener on 'normal' priority.

```typescript
view.on( 'render', () => {
	// Rendering to the DOM is complete.
} );
```

This event is useful when you want to update interface elements after the rendering, e.g. position of the balloon panel. If you wants to change view structure use [post-fixers](module_engine_view_document-ViewDocument.md#function-registerPostFixer).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L846)

#### Parameters

* `eventInfo: EventInfo`

  An object containing information about the fired event.

<a id="event-scrollToTheSelection">

### `scrollToTheSelection( eventInfo, <anonymous>, <anonymous> )`

An event fired at the moment of [`scrollToTheSelection`](#function-scrollToTheSelection) being called. It carries two objects in its payload (`args`):

* The first argument is the [object containing data](module_engine_view_view-ViewScrollToTheSelectionEventData.md) that gets passed down to the [`scrollViewportToShowTarget`](module_utils_dom_scroll.md#function-scrollViewportToShowTarget) helper. If some event listener modifies it, it can adjust the behavior of the scrolling (e.g. include additional `viewportOffset`).
* The second argument corresponds to the original arguments passed to [`scrollViewportToShowTarget`](module_utils_dom_scroll.md#function-scrollViewportToShowTarget). It allows listeners to re-execute the `scrollViewportToShowTarget()` method with its original arguments if there is such a need, for instance, if the integration requires re–scrolling after certain interaction.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L864)

#### Parameters

* `eventInfo: EventInfo`

  An object containing information about the fired event.

* `<anonymous>: ViewScrollToTheSelectionEventData`

* `<anonymous>: Parameters<EditingView[ 'scrollToTheSelection' ]>[ 0 ]`

<a id="event-set:hasDomSelection">

### `set:hasDomSelection( eventInfo, name, value, oldValue )`

Fired when the `hasDomSelection` property is going to be set but is not set yet (before the `change` event is fired).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L126)

#### Parameters

* `eventInfo: EventInfo`

  An object containing information about the fired event.

* `name: string`

  Name of the changed property (`hasDomSelection`).

* `value: boolean`

  New value of the `hasDomSelection` property with given key or `null`, if operation should remove property.

* `oldValue: boolean`

  Old value of the `hasDomSelection` property with given key or `null`, if property was not set before.

<a id="event-set:isRenderingInProgress">

### `set:isRenderingInProgress( eventInfo, name, value, oldValue )`

Fired when the `isRenderingInProgress` property is going to be set but is not set yet (before the `change` event is fired).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/view.ts#L118)

#### Parameters

* `eventInfo: EventInfo`

  An object containing information about the fired event.

* `name: string`

  Name of the changed property (`isRenderingInProgress`).

* `value: boolean`

  New value of the `isRenderingInProgress` property with given key or `null`, if operation should remove property.

* `oldValue: boolean`

  Old value of the `isRenderingInProgress` property with given key or `null`, if property was not set before.

<a id="event-set:%7Bproperty%7D">

### `set:{property}( eventInfo, name, value, oldValue )` _(inherited)_

Fired when a property value is going to be set but is not set yet (before the `change` event is fired).

You can control the final value of the property by using the [event's `return` property](module_utils_eventinfo-EventInfo.md#member-return).

```typescript
observable.set( 'prop', 1 );

observable.on<ObservableSetEvent<number>>( 'set:prop', ( evt, propertyName, newValue, oldValue ) => {
	console.log( `Value is going to be changed from ${ oldValue } to ${ newValue }` );
	console.log( `Current property value is ${ observable[ propertyName ] }` );

	// Let's override the value.
	evt.return = 3;
} );

observable.on<ObservableChangeEvent<number>>( 'change:prop', ( evt, propertyName, newValue, oldValue ) => {
	console.log( `Value has changed from ${ oldValue } to ${ newValue }` );
} );

observable.prop = 2; // -> 'Value is going to be changed from 1 to 2'
					 // -> 'Current property value is 1'
					 // -> 'Value has changed from 1 to 3'
```

**Note:** The event is fired even when the new value is the same as the old value.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/observablemixin.ts#L1228)

#### Parameters

* `eventInfo: EventInfo`

  An object containing information about the fired event.

* `name: string`

  The property name.

* `value: TValue`

  The new property value.

* `oldValue: TValue`

  The previous property value.

---

Full index of the CKEditor 5 API reference: [llms.txt](llms.txt)
