Google Drive SDK

Class gapi.drive.realtime.CollaborativeList

A collaborative list. A list can contain other Realtime collaborative objects, custom collaborative objects, JavaScript primitive values, or JavaScript objects that can be serialized to JSON.

Changes to the list will automatically be synced with the server and other collaborators. To listen for changes, add EventListeners for the following event types:

  • gapi.drive.realtime.EventType.VALUES_ADDED
  • gapi.drive.realtime.EventType.VALUES_REMOVED
  • gapi.drive.realtime.EventType.VALUES_SET

This class should not be instantiated directly. To create a new list, use gapi.drive.realtime.Model.prototype.createList().

Namespacegapi.drive.realtimeClassgapi.drive.realtime.CollaborativeList

Summary
ClassCollaborativeList A collaborative list. A list can contain other Realtime collaborative objects, custom collaborative objects, JavaScript primitive values, or JavaScript objects that can be serialized to JSON.

Changes to the list will automatically be synced with the server and other collaborators. To listen for changes, add EventListeners for the following event types:

  • gapi.drive.realtime.EventType.VALUES_ADDED
  • gapi.drive.realtime.EventType.VALUES_REMOVED
  • gapi.drive.realtime.EventType.VALUES_SET

This class should not be instantiated directly. To create a new list, use gapi.drive.realtime.Model.prototype.createList().

FunctionasArray Returns a copy of the contents of this collaborative list as a Javascript array. Changes to the returned object will not affect the original collaborative list.
Functionclear Removes all values from the list.
Functionget Gets the value at the given index.
FunctionindexOf Returns the first index of the given value, or -1 if it cannot be found.
Functioninsert Inserts an item into the list at a given index.
FunctioninsertAll Inserts a list of items into the list at a given index.
FunctionlastIndexOf Returns the last index of the given value, or -1 if it cannot be found.
Functionpush Adds an item to the end of the list.
FunctionpushAll Adds an array of values to the end of the list.
FunctionregisterReference Creates an IndexReference at the given index. If canBeDeleted is true, then a delete over the index will delete the reference. Otherwise the reference will shift to the beginning of the deleted range.
Functionremove Removes the item at the given index from the list.
FunctionremoveRange Removes the items between startIndex (inclusive) and endIndex (exclusive).
FunctionremoveValue Removes the first instance of the given value from the list.
FunctionreplaceRange Replaces items in the list with the given items, starting at the given index.
Functionset Sets the item at the given index
FunctiongetId Returns the object ID.
FunctiontoString Returns a string representation of this collaborative object.
FunctionaddEventListener 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.
FunctionremoveEventListener 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.
Fieldlength The number of entries in the list. Assign to this field to reduce the size of the list. Note that the length given must be < or equal to the current size. The length of a list cannot be extended in this way.
Fieldid The ID of the collaborative object. Readonly.

Constructor

CollaborativeList(model)

A collaborative list. A list can contain other Realtime collaborative objects, custom collaborative objects, JavaScript primitive values, or JavaScript objects that can be serialized to JSON.

Changes to the list will automatically be synced with the server and other collaborators. To listen for changes, add EventListeners for the following event types:

  • gapi.drive.realtime.EventType.VALUES_ADDED
  • gapi.drive.realtime.EventType.VALUES_REMOVED
  • gapi.drive.realtime.EventType.VALUES_SET

This class should not be instantiated directly. To create a new list, use gapi.drive.realtime.Model.prototype.createList().

Extends:
Classgapi.drive.realtime.CollaborativeObject
Parameters:
Classgapi.drive.realtime.Model modelThe document model.
See also:
Functiongapi.drive.realtime.Model.createList

Functions

asArray() -> Array.<*>

Returns a copy of the contents of this collaborative list as a Javascript array. Changes to the returned object will not affect the original collaborative list.

Returns:
Array.<*> A copy of the contents of this collaborative list.

clear()

Removes all values from the list.

get(index) -> *

Gets the value at the given index.

Parameters:
number indexThe index.
Returns:
* The value at the given index.

indexOf(value, opt_comparatorFn) -> number

Returns the first index of the given value, or -1 if it cannot be found.

Parameters:
* valueThe value to find.
function(*, *): boolean= opt_comparatorFnOptional comparator function used to determine the equality of two items.
Returns:
number The index of the given value, or -1 if it cannot be found.

insert(index, value)

Inserts an item into the list at a given index.

Parameters:
number indexThe index to insert at.
* valueThe value to add.

insertAll(index, values)

Inserts a list of items into the list at a given index.

Parameters:
number indexThe index at which to insert.
Array.<*> valuesThe values to insert.

lastIndexOf(value, opt_comparatorFn) -> number

Returns the last index of the given value, or -1 if it cannot be found.

Parameters:
* valueThe value to find.
function(*, *): boolean= opt_comparatorFnOptional comparator function used to determine the equality of two items.
Returns:
number The index of the given value, or -1 if it cannot be found.

push(value) -> number

Adds an item to the end of the list.

Parameters:
* valueThe value to add.
Returns:
number The new array length.

pushAll(values)

Adds an array of values to the end of the list.

Parameters:
Array.<*> valuesThe values to add.

registerReference(index, canBeDeleted) -> Classgapi.drive.realtime.IndexReference

Creates an IndexReference at the given index. If canBeDeleted is true, then a delete over the index will delete the reference. Otherwise the reference will shift to the beginning of the deleted range.

Parameters:
number indexThe index of the reference.
boolean canBeDeletedWhether this index is deleted when there is a delete of a range covering this index.
Returns:
Classgapi.drive.realtime.IndexReference The newly registered reference.

remove(index)

Removes the item at the given index from the list.

Parameters:
number indexThe index of the item to remove.

removeRange(startIndex, endIndex)

Removes the items between startIndex (inclusive) and endIndex (exclusive).

Parameters:
number startIndexThe start index of the range to remove (inclusive).
number endIndexThe end index of the range to remove (exclusive).

removeValue(value) -> boolean

Removes the first instance of the given value from the list.

Parameters:
* valueThe value to remove.
Returns:
boolean Whether the item was removed.

replaceRange(index, values)

Replaces items in the list with the given items, starting at the given index.

Parameters:
number indexThe index to set at.
Array.<*> valuesThe values to insert.

set(index, value)

Sets the item at the given index

Parameters:
number indexThe index to insert at.
* valueThe value to set.

getId() -> string

Returns the object ID.

Returns:
string The id.

toString() -> string

Returns a string representation of this collaborative object.

Returns:
string A string representation.

addEventListener(type, handler, 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:
string typeThe type of the event to listen for.
Function|Object handlerThe function to handle the event. The handler can also be an object that implements the handleEvent method which takes the event object as argument.
boolean= opt_captureIn DOM-compliant browsers, this determines whether the listener is fired during the capture or bubble phase of the event.

removeEventListener(type, handler, 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:
string typeThe type of the event to listen for.
Function|Object handlerThe function to handle the event. The handler can also be an object that implements the handleEvent method which takes the event object as argument.
boolean= opt_captureIn DOM-compliant browsers, this determines whether the listener is fired during the capture or bubble phase of the event.

Fields

length -> number

The number of entries in the list. Assign to this field to reduce the size of the list. Note that the length given must be < or equal to the current size. The length of a list cannot be extended in this way.

id -> string

The ID of the collaborative object. Readonly.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.