Class: Model

Properties
beginCreationCompoundOperation void

Initiates a creation compound operation, which is used to set the document's initial state. This function is not a prototype method because it is only used internally.

bytesUsed number

An estimate of the number of bytes used by data stored in the model.

canRedo boolean

True if the model can currently redo.

canUndo boolean

True if the model can currently undo.

Methods
createJsObject(typeName) non-null Object

Creates the native JS object for a given collaborative object type.

addEventListener(type, listener[, opt_capture]) void

Adds an event listener to the event target. The same handler can only be added once per the type. Even if you add the same handler multiple times using the same type then it will only be called once when the event is dispatched.

beginCompoundOperation([opt_name][, opt_isUndoable]) void

Starts a compound operation. If a name is given, that name will be recorded in the mutation for use in revision history, undo menus, etc. When beginCompoundOperation() is called, all subsequent edits to the data model will be batched together in the undo stack and revision history until endCompoundOperation() is called. Compound operations may be nested inside other compound operations.

If the root compound operation is undoable, all nested compound operations must be undoable as well. If the root compound operation is non-undoable, nested operations can be undoable, although the entire operation will obey the root's opt_isUndoable value.

Note that the compound operation MUST start and end in the same synchronous execution block. If this invariant is violated, the data model will become invalid and all future changes will fail.

create(ref, ...var_args) non-null Object

Creates and returns a new collaborative object. This can be used to create custom collaborative objects. For built in types, use the specific create* functions.

createList([opt_initialValue]) non-null Object

Creates a collaborative list.

createMap([opt_initialValue]) non-null Object

Creates a collaborative map.

createString([opt_initialValue]) non-null Object

Creates a collaborative string.

endCompoundOperation() void

Ends a compound operation. This method will throw an exception if no compound operation is in progress.

getRoot() gapi.drive.realtime.CollaborativeMap

Returns the root of the object model, or null if this Realtime model has not been initialized.

isReadOnly() boolean

The mode of the document. If true, the document is read-only. If false, it is editable.

redo() void

Redo the last thing the active collaborator undid.

removeAllEventListeners() void

Removes all event listeners from this object.

removeEventListener(type, listener[, opt_capture]) void

Removes an event listener from the event target. The handler must be the same object as the one added. If the handler has not been added then nothing is done.

serverRevision() number

The current server revision number for this model. The revision number begins at 1 (the initial empty model) and is incremented each time the model is changed on the server (either by the current session or any other collaborator). Because this revision number includes only changes that the server knows about, it is only updated while this client is connected to the Realtime API server and it does not include changes that have not yet been saved to the server.

toJson([opt_appId][, opt_revision]) string

Serializes this data model to a JSON-based format which is compatible with the Realtime API's import/export REST API. The exported JSON can also be used with gapi.drive.realtime.loadFromJson to load an in-memory version of this data model which does not require a network connection. See https://developers.google.com/drive/v2/reference/realtime/update for more information.

undo() void

Undo the last thing the active collaborator did.

new Model()

This class should not be instantiated directly. The collaborative model is generated during the document load process. The model can be initialized by passing an initializer function to gapi.drive.realtime.load.

Extends
gapi.drive.realtime.EventTarget
See also
gapi.drive.realtime.load()

Properties

static
beginCreationCompoundOperation

Initiates a creation compound operation, which is used to set the document's initial state. This function is not a prototype method because it is only used internally.

Parameter

Name Type Optional Description

model

gapi.drive.realtime.Model

 

The model to begin the creation compound operation on.

Value must not be null.

bytesUsed  number

An estimate of the number of bytes used by data stored in the model.

canRedo  boolean

True if the model can currently redo.

canUndo  boolean

True if the model can currently undo.

Methods

static
createJsObject(typeName) → Object

Creates the native JS object for a given collaborative object type.

Parameter

Name Type Optional Description

typeName

string

 

The type to create.

Returns

non-null Object The JS object.

addEventListener(type, listener[, opt_capture])

Adds an event listener to the event target. The same handler can only be added once per the type. Even if you add the same handler multiple times using the same type then it will only be called once when the event is dispatched.

Parameters

Name Type Optional Description

type

string

 

The type of the event to listen for.

listener

(non-null function() or non-null EventListener)

 

The function to handle the event. The handler can also be an object that implements the handleEvent method which takes the event object as argument.

opt_capture

boolean

Yes

Whether to handle the event target in the capture phase instead of the bubble phase.

Inherited from
gapi.drive.realtime.EventTarget#addEventListener

beginCompoundOperation([opt_name][, opt_isUndoable])

Starts a compound operation. If a name is given, that name will be recorded in the mutation for use in revision history, undo menus, etc. When beginCompoundOperation() is called, all subsequent edits to the data model will be batched together in the undo stack and revision history until endCompoundOperation() is called. Compound operations may be nested inside other compound operations.

If the root compound operation is undoable, all nested compound operations must be undoable as well. If the root compound operation is non-undoable, nested operations can be undoable, although the entire operation will obey the root's opt_isUndoable value.

Note that the compound operation MUST start and end in the same synchronous execution block. If this invariant is violated, the data model will become invalid and all future changes will fail.

Parameters

Name Type Optional Description

opt_name

string

Yes

An optional name for this compound operation.

opt_isUndoable

boolean

Yes

An option to make this operation undoable.

create(ref, ...var_args) → Object

Creates and returns a new collaborative object. This can be used to create custom collaborative objects. For built in types, use the specific create* functions.

Parameters

Name Type Optional Description

ref

(function(any type) or string)

 

An object constructor or type name.

var_args

any type

 

Arguments to the newly-created object's initialize() method.

Value can be repeated.

Returns

non-null Object A new collaborative object.

createList([opt_initialValue]) → Object

Creates a collaborative list.

Parameter

Name Type Optional Description

opt_initialValue

Array of any type

Yes

Initial value for the list.

Value must not be null.

Returns

non-null Object A collaborative list.

createMap([opt_initialValue]) → Object

Creates a collaborative map.

Parameter

Name Type Optional Description

opt_initialValue

Array of any type

Yes

Initial value for the map.

Value must not be null.

Returns

non-null Object A collaborative map.

createString([opt_initialValue]) → Object

Creates a collaborative string.

Parameter

Name Type Optional Description

opt_initialValue

string

Yes

Sets the initial value for this string.

Value must not be null.

Returns

non-null Object A collaborative string.

endCompoundOperation()

Ends a compound operation. This method will throw an exception if no compound operation is in progress.

getRoot() → gapi.drive.realtime.CollaborativeMap

Returns the root of the object model, or null if this Realtime model has not been initialized.

Returns

gapi.drive.realtime.CollaborativeMap The root of the object model.

isReadOnly()

The mode of the document. If true, the document is read-only. If false, it is editable.

redo()

Redo the last thing the active collaborator undid.

removeAllEventListeners()

Removes all event listeners from this object.

Inherited from
gapi.drive.realtime.EventTarget#removeAllEventListeners

removeEventListener(type, listener[, opt_capture])

Removes an event listener from the event target. The handler must be the same object as the one added. If the handler has not been added then nothing is done.

Parameters

Name Type Optional Description

type

gapi.drive.realtime.EventType

 

The type of the event to listen for.

listener

(non-null function() or non-null EventListener)

 

The function to or EventListener to remove.

opt_capture

boolean

Yes

Whether to handle the event target in the capture phase instead of the bubble phase.

Inherited from
gapi.drive.realtime.EventTarget#removeEventListener

serverRevision()

The current server revision number for this model. The revision number begins at 1 (the initial empty model) and is incremented each time the model is changed on the server (either by the current session or any other collaborator). Because this revision number includes only changes that the server knows about, it is only updated while this client is connected to the Realtime API server and it does not include changes that have not yet been saved to the server.

toJson([opt_appId][, opt_revision]) → string

Serializes this data model to a JSON-based format which is compatible with the Realtime API's import/export REST API. The exported JSON can also be used with gapi.drive.realtime.loadFromJson to load an in-memory version of this data model which does not require a network connection. See https://developers.google.com/drive/v2/reference/realtime/update for more information.

Parameters

Name Type Optional Description

opt_appId

string

Yes

An optional developer-sepcified application ID to include in the exported model. This value is provided automatically when a document is exported via the Realtime API's REST API, but it is not required.

opt_revision

number

Yes

An optional developer-specified revision number to include in the exported model. This value is provided automatically when a document is exported via the Realtime API's REST API, but it is not required.

Returns

string The JSON-serialized data model.

undo()

Undo the last thing the active collaborator did.

Send feedback about...

Realtime API
Realtime API