Class: SyncEngine
The core engine that manages the editor state and coordinates synchronization.
It implements a transaction-based update cycle:
- Receives a
Transactiondescribing changes. - Updates the
EditorState(Source). - Triggers the
Parser(Source -> CST). - Triggers the
XMLBinder(CST -> Model). - Notifies listeners (including
SchemaViews) of changes.
Constructors
Constructor
new SyncEngine(
source,grammar):SyncEngine
Parameters
source
string
grammar
Grammar = defaultGrammar
Returns
SyncEngine
Accessors
cst
Get Signature
get cst():
CST|null
Returns
CST | null
grammar
Get Signature
get grammar():
Grammar
Returns
model
Get Signature
get model():
ModelElement|null
Returns
ModelElement | null
source
Get Signature
get source():
string
Returns
string
state
Get Signature
get state():
EditorState
Returns
Methods
applyPatch()
applyPatch(
start,end,text,meta?):void
Apply a programmatic change derived from Model operations. This is the "Application -> Source" flow.
Parameters
start
number
end
number
text
string
meta?
Record<string, any>
Returns
void
Deprecated
Use dispatch(new Transaction(state).replace(...)) instead.
dispatch()
dispatch(
tr):void
Applies a transaction to the engine, updating the state and notifying listeners. This is the single point of truth for all state transitions in the system.
It handles:
- History recording (Undo/Redo)
- Incremental Parsing and Reconciliation
- Event Dispatching
- Collaboration hooks
Parameters
tr
The transaction to apply.
Returns
void
insertNode()
insertNode(
parent,child,index,meta?):void
Parameters
parent
child
index
number
meta?
Record<string, any>
Returns
void
Deprecated
Use dispatch(new TransactionBuilder(engine.state, engine.binder).insertNode(...)) instead.
on()
on(
handler): () =>void
Subscribe to model changes.
Parameters
handler
Returns
():
void
Returns
void
redo()
redo():
void
Returns
void
removeNode()
removeNode(
parent,child,meta?):void
Parameters
parent
child
meta?
Record<string, any>
Returns
void
Deprecated
Use dispatch(new TransactionBuilder(engine.state, engine.binder).removeNode(...)) instead.
replaceNode()
replaceNode(
target,content,meta?):void
Parameters
target
content
meta?
Record<string, any>
Returns
void
Deprecated
Use dispatch(new TransactionBuilder(engine.state, engine.binder).replaceNode(...)) instead.
setAttribute()
setAttribute(
modelNode,key,value,meta?):void
Parameters
modelNode
key
string
value
string
meta?
Record<string, any>
Returns
void
Deprecated
Use dispatch(new TransactionBuilder(engine.state, engine.binder).setAttribute(...)) instead.
setCollabBridge()
setCollabBridge(
bridge):void
Parameters
bridge
Returns
void
undo()
undo():
void
Returns
void
updateSource()
updateSource(
from,to,text,meta?):void
Update the source code (e.g. from text editor). Handles history recording and incremental parsing.
Parameters
from
number
to
number
text
string
meta?
Record<string, any>
Returns
void
updateText()
updateText(
modelNode,text,meta?):void
Parameters
modelNode
text
string
meta?
Record<string, any>
Returns
void
Deprecated
Use dispatch(new TransactionBuilder(engine.state, engine.binder).updateText(...)) instead.