Expand all

ve.dm.SurfaceSynchronizer

Constructor

new ve.dm.SurfaceSynchronizer(surface, documentId, [config]) #

DataModel surface synchronizer.

Parameters:

Name Type Attributes Description
surface ve.dm.Surface

Surface model to synchronize

documentId string

Document ID

config Object optional

Configuration options

Properties:
Name Type Attributes Description
server string optional

IO server

defaultName string optional

Default username

Mixes in:
Source:
DataModel surface synchronizer.

Methods

applyNewSelections(newSelections, [changeOrTx]) #

Translate incoming selections by change, then apply them and fire authorSelect

Parameters:

Name Type Attributes Description
newSelections Object

Each author (key) maps to a new incoming ve.dm.Selection

changeOrTx ve.dm.Change | ve.dm.Transaction optional

Object to translate over, if any

Source:

Fires:

Translate incoming selections by change, then apply them and fire authorSelect

destroy() #

Destroy the synchronizer

Source:
Destroy the synchronizer

getAuthorData([authorId]) → {Object} #

Get author data object

Parameters:

Name Type Attributes Description
authorId number optional

Author ID, defaults to current author

Source:

Returns:

Author object, containing 'name' and 'color'

Type
Object
Get author data object

getChangeSince() #

onInitDoc(data) #

Respond to an initDoc event from the server, catching us up on the prior history of the document.

Parameters:

Name Type Description
data Object
Properties:
Name Type Description
history Object

Serialized change representing the server's history

authors Object

Object mapping author IDs to author data objects (name/color)

Source:

Fires:

Respond to an initDoc event from the server, catching us up on the prior history of the document.

onNewChange(serializedChange) #

Respond to a newChange event from the server, signalling a newly committed change

If the commited change is by another author, then:

  • Rebase uncommitted changes over the committed change
  • If there is a rebase rejection, then apply its inverse to the document
  • Apply the rebase-transposed committed change to the document
  • Rewrite history to have the committed change followed by rebased uncommitted changes

If the committed change is by the local author, then it is already applied to the document and at the correct point in the history: just move the commit pointer.

Parameters:

Name Type Description
serializedChange Object

Serialized ve.dm.Change that the server has applied

Source:

Respond to a newChange event from the server, signalling a newly committed change

If the commited change is by another author, then:

  • Rebase uncommitted changes over the committed change
  • If there is a rebase rejection, then apply its inverse to the document
  • Apply the rebase-transposed committed change to the document
  • Rewrite history to have the committed change followed by rebased uncommitted changes

If the committed change is by the local author, then it is already applied to the document and at the correct point in the history: just move the commit pointer.

onRegistered(data) #

Respond to a "registered" event from the server

Parameters:

Name Type Description
data Object
Properties:
Name Type Description
authorId number

The author ID allocated by the server

token string
Source:

Fires:

Respond to a "registered" event from the server

onSurfaceHistory() #

Respond to transactions happening on the document. Ignores transactions applied by SurfaceSynchronizer itself.

Source:
Respond to transactions happening on the document.

onSurfaceSelect() #

Respond to selection changes.

Source:
Respond to selection changes.

pauseChanges() #

Pause sending/receiving changes

removeFromHistory() #

resumeChanges() #

Resume sending/receiving changes

Events

authorChange(authorId) #

Parameters:

Name Type Description
authorId number

The author whose data has changed

Source:

authorSelect(authorId) #

Parameters:

Name Type Description
authorId number

The author whose selection has changed

Source:

initDoc(error) #

Parameters:

Name Type Description
error Error

Error, if there was a problem initializing the document

Source:

pause() #

The synchronizer is paused or resumes

Source:
The synchronizer is paused or resumes