Expand all

ve.dm.TransactionProcessor

Classes

modifiers
Modifier methods.
processors
Processing methods.

Constructor

new ve.dm.TransactionProcessor(doc, transaction, isStaging) #

DataModel transaction processor.

This class reads operations from a transaction and applies them one by one. It's not intended to be used directly; use {ve.dm.Document#commit} instead.

NOTE: Instances of this class are not recyclable: you can only call .process() on them once.

Parameters:

Name Type Description
doc ve.dm.Document
transaction ve.dm.Transaction
isStaging boolean

Transaction is being applied in staging mode

Source:
DataModel transaction processor.

Properties

largeReplaceFraction :numberstatic #

Fraction of the attached root that a single replace must remove or insert to use the fast rebuild path instead of the incremental per-node TreeModifier path (T189557).

Type:

  • number
Source:

Fraction of the attached root that a single replace must remove or insert to use the fast rebuild path instead of the incremental per-node TreeModifier path (T189557).

largeReplaceMinimum :numberstatic #

Minimum number of linear-model offsets a single replace must remove or insert to use the fast rebuild path. This limit applies together with ve.dm.TransactionProcessor.largeReplaceFraction.

The fraction becomes small when the document is small. In a nearly empty document, a few characters are more than half of it. The rebuild replaces the ContentEditable node that holds the cursor. This stops an IME composition, because the composition belongs to that text node (T435688).

Type:

  • number
Source:

Minimum number of linear-model offsets a single replace must remove or insert to use the fast rebuild path.

Methods

advanceCursor(increment)private #

Advance the main data cursor.

Parameters:

Name Type Description
increment number

Number of positions to increment the cursor by

Source:
Advance the main data cursor.

applyLargeReplace(largeReplace)private #

Apply a large replace as a single linear splice plus a one-pass tree rebuild, instead of TreeModifier's per-node application. See #getLargeReplaceOp.

Parameters:

Name Type Description
largeReplace Object

{ op, offset } from #getLargeReplaceOp

Source:

Apply a large replace as a single linear splice plus a one-pass tree rebuild, instead of TreeModifier's per-node application.

applyModifications()private #

Apply all modifications queued through #queueModification, and add their rollback functions to this.rollbackQueue.

Source:

Apply all modifications queued through #queueModification, and add their rollback functions to this.rollbackQueue.

emitQueuedEvents()private #

Emit all events queued through #queueEvent.

Source:
Emit all events queued through #queueEvent.

executeOperation(op)private #

Execute an operation.

Parameters:

Name Type Description
op Object

Operation object to execute

Throws:

Operation type is not supported

Type
Error
Source:
Execute an operation.

getLargeReplaceOp() → {Object|null}private #

Detect a single large replace that can take the fast rebuild path. The transaction must hold retains plus exactly one replace, and no attribute ops. The replace must remove or insert at least ve.dm.TransactionProcessor.largeReplaceFraction of the attached root, and at least ve.dm.TransactionProcessor.largeReplaceMinimum offsets. It must also span more than one paragraph.

Returns:

{ op, offset } for the qualifying replace (offset is its linear-model offset), else null to use the incremental TreeModifier path

Type
Object | null
Source:
Detect a single large replace that can take the fast rebuild path.

process()private #

Process all operations.

When all operations are done being processed, the document will be synchronized.

Source:
Process all operations.

queueEvent(node, name, […args])private #

Queue an event to be emitted on a node.

Duplicate events will be ignored only if all arguments match exactly (i.e. are reference-equal).

Parameters:

Name Type Attributes Description
node ve.dm.Node
name string

Event name

args any optional
repeatable

Additional arguments to be passed to the event when fired

Source:
Queue an event to be emitted on a node.

queueModification(modification)private #

Queue a modification.

Parameters:

Name Type Description
modification Object

Object describing the modification

Properties:
Name Type Attributes Description
type string

Name of a method in ve.dm.TransactionProcessor.modifiers

args Array optional

Arguments to pass to this method

Throws:

Unrecognized modification type

Type
Error
Source:
Queue a modification.

queueUndoFunction(func) #

Queue an undo function. If an exception is thrown while modifying, #rollbackModifications will invoke these functions in reverse order.

Parameters:

Name Type Description
func function

Undo function to add to the queue

Source:
Queue an undo function.

rollbackModifications()private #

Roll back all modifications that have been applied so far. This invokes the callbacks returned by the modifier functions.

Source:
Roll back all modifications that have been applied so far.

spansMultipleParagraphs(data) → {boolean}privatestatic #

Check if linear data spans more than one paragraph.

A source-mode document is flat, so each open element starts a paragraph. Data that does not start with an open element continues the paragraph before it.

Parameters:

Name Type Description
data Array

Linear data from a replace operation

Returns:

The data spans more than one paragraph

Type
boolean
Source:
Check if linear data spans more than one paragraph.