Creates a downcast dispatcher instance.
Additional properties for an interface that will be passed to events fired by the downcast dispatcher.
Readonly Internal_A template for an interface passed by the dispatcher to the event callbacks.
Starts a conversion of a model range and the provided markers.
The inserted range.
The map of markers that should be down-casted.
The view writer that should be used to modify the view document.
Optionaloptions: Record<string, unknown>Optional options object passed to convertionApi.options.
Converts changes buffered in the given module:engine/model/differ~Differ model differ and fires conversion events based on it.
The differ object with buffered changes.
Markers related to the model fragment to convert.
The view writer that should be used to modify the view document.
Starts the model selection conversion.
Fires events for a given module:engine/model/selection~ModelSelection selection to start the selection conversion.
The selection to convert.
Markers connected with the converted model.
View writer that should be used to modify the view document.
Delegates selected events to another module:utils/emittermixin~Emitter. For instance:
emitterA.delegate( 'eventX' ).to( emitterB );
emitterA.delegate( 'eventX', 'eventY' ).to( emitterC );
then eventX is delegated (fired by) emitterB and emitterC along with data:
emitterA.fire( 'eventX', data );
and eventY is delegated (fired by) emitterC along with data:
emitterA.fire( 'eventY', data );
Event names that will be delegated to another emitter.
Fires an event, executing all callbacks registered for it.
The first parameter passed to callbacks is an module:utils/eventinfo~EventInfo object,
followed by the optional args provided in the fire() method call.
The type describing the event. See module:utils/emittermixin~BaseEvent.
The name of the event or EventInfo object if event is delegated.
Additional arguments to be passed to the callbacks.
By default the method returns undefined. However, the return value can be changed by listeners
through modification of the module:utils/eventinfo~EventInfo#return evt.return's property (the event info
is the first param of every callback).
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.
// 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 module:utils/eventinfo~EventInfo#stop stop the event and set the module:utils/eventinfo~EventInfo#return return value of the #fire method.
The type describing the event. See module:utils/emittermixin~BaseEvent.
The object that fires the event.
The name of the event.
The function to be called on event.
Optionaloptions: GetCallbackOptions<TEvent>Additional options.
Stops executing the callback on the given event.
Shorthand for #stopListening this.stopListening( this, event, callback ).
The name of the event.
The function to stop being called.
Registers a callback function to be executed when an event is fired.
Shorthand for #listenTo this.listenTo( this, event, callback, options ) (it makes the emitter
listen on itself).
The type descibing the event. See module:utils/emittermixin~BaseEvent.
The name of the event.
The function to be called on event.
Optionaloptions: GetCallbackOptions<TEvent>Additional options.
Registers a callback function to be executed on the next time the event is fired only. This is similar to calling #on followed by #off in the callback.
The type descibing the event. See module:utils/emittermixin~BaseEvent.
The name of the event.
The function to be called on event.
Optionaloptions: GetCallbackOptions<TEvent>Additional options.
Stops delegating events. It can be used at different levels:
Optionalevent: stringThe name of the event to stop delegating. If omitted, stops it all delegations.
Optionalemitter: Emitter(requires event) The object to stop delegating a particular event to.
If omitted, stops delegation of event to all emitters.
Stops listening for events. It can be used at different levels:
Optionalemitter: EmitterThe object to stop listening to. If omitted, stops it for all objects.
Optionalevent: string(Requires the emitter) The name of the event to stop listening to. If omitted, stops it
for all events from emitter.
Optionalcallback: Function(Requires the event) The function to be removed from the call list for the given
event.
The downcast dispatcher is a central point of downcasting (conversion from the model to the view), which is a process of reacting to changes in the model and firing a set of events. The callbacks listening to these events are called converters. The converters' role is to convert the model changes to changes in view (for example, adding view nodes or changing attributes on view elements).
During the conversion process, downcast dispatcher fires events basing on the state of the model and prepares data for these events. It is important to understand that the events are connected with the changes done on the model, for example: "a node has been inserted" or "an attribute has changed". This is in contrary to upcasting (a view-to-model conversion) where you convert the view state (view nodes) to a model tree.
The events are prepared basing on a diff created by the module:engine/model/differ~Differ Differ, which buffers them and then passes to the downcast dispatcher as a diff between the old model state and the new model state.
Note that because the changes are converted, there is a need to have a mapping between the model structure and the view structure. To map positions and elements during the downcast (a model-to-view conversion), use module:engine/conversion/mapper~Mapper.
Downcast dispatcher fires the following events for model tree changes:
insert– If a range of nodes was inserted to the model tree.remove– If a range of nodes was removed from the model tree.attribute– If an attribute was added, changed or removed from a model node.For module:engine/conversion/downcastdispatcher~DowncastDispatcher#event:insert
insertand module:engine/conversion/downcastdispatcher~DowncastDispatcher#event:attributeattribute, the downcast dispatcher generates module:engine/conversion/modelconsumable~ModelConsumable consumables. These are used to have control over which changes have already been consumed. It is useful when some converters overwrite others or convert multiple changes (for example, it converts an insertion of an element and also converts that element's attributes during the insertion).Additionally, downcast dispatcher fires events for module:engine/model/markercollection~Marker marker changes:
addMarker– If a marker was added.removeMarker– If a marker was removed.Note that changing a marker is done through removing the marker from the old range and adding it to the new range, so both of these events are fired.
Finally, a downcast dispatcher also handles firing events for the module:engine/model/selection model selection conversion:
selection– Converts the selection from the model to the view.attribute– Fired for every selection attribute.addMarker– Fired for every marker that contains a selection.Unlike the model tree and the markers, the events for selection are not fired for changes but for a selection state.
When providing custom listeners for a downcast dispatcher, remember to check whether a given change has not been module:engine/conversion/modelconsumable~ModelConsumable#consume consumed yet.
When providing custom listeners for a downcast dispatcher, keep in mind that you should not stop the event. If you stop it, then the default converter at the
lowestpriority will not trigger the conversion of this node's attributes and child nodes.When providing custom listeners for a downcast dispatcher, remember to use the provided module:engine/view/downcastwriter~ViewDowncastWriter view downcast writer to apply changes to the view document.
You can read more about conversion in the following guide:
An example of a custom converter for the downcast dispatcher: