Hide

Class: CollaborativeList

Property
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 less than or equal to the current size. The length of a list cannot be extended in this way.

Methods
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.

asArray() non-null Array of any type

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

clear() void

Removes all values from the list.

get(index) any type

Gets the value at the given index.

id() string

The id of this collaborative object. Read-only.

indexOf(value, opt_comparatorFn) number

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

insert(index, value) void

Inserts an item into the list at a given index.

insertAll(index, values) void

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

lastIndexOf(value, opt_comparatorFn) number

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

move(index, destinationIndex) void

Moves a single element in this list (at index) to immediately before destinationIndex. Both indices are with respect to the position of elements before the move.

For example, given the list: ['A', 'B', 'C']

  • move(0, 0) is a no-op
  • move(0, 1) is a no-op
  • move(0, 2) yields ['B', 'A', 'C'] ('A' is moved to immediately before 'C')
  • move(0, 3) yields ['B', 'C', 'A'] ('A' is moved to immediately before an imaginary element after the list end)
  • move(1, 0) yields ['B', 'A', 'C'] ('B' is moved to immediately before 'A')
  • move(1, 1) is a no-op
  • move(1, 2) is a no-op
  • move(1, 3) yields ['A', 'C', 'B'] ('B' is moved to immediately before an imaginary element after the list end)
moveToList(index, destination, destinationIndex) void

Moves a single element in this list (at index) to immediately before destinationIndex in the list destination. Both indices are with respect to the position of elements before the move.

If the provided destination is this list, this function is identical to move(index, destinationIndex).

push(value) number

Adds an item to the end of the list.

pushAll(values) void

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

registerReference(index, deleteMode) non-null gapi.drive.realtime.IndexReference

Creates an IndexReference pointing at the given index in this list.

remove(index) void

Removes the item at the given index from the list.

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.

removeRange(startIndex, endIndex) void

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

removeValue(value) boolean

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

replaceRange(index, values) void

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

set(index, value) void

Sets the item at the given index

toString() string

Returns a string representation of this collaborative object.

type() string

The type of this collaborative object. For standard collaborative objects, see gapi.drive.realtime.CollaborrativeType for possible values; for custom collaborative objects, this value is application-defined.

new CollaborativeList()

This class should not be instantiated directly. To create a new list, use model.createList().

Extends
gapi.drive.realtime.CollaborativeObject
See also
gapi.drive.realtime.Model.prototype.createList()
gapi.drive.realtime.EventType

Property

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 less than or equal to the current size. The length of a list cannot be extended in this way.

Methods

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

asArray() → Array of any type

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

Returns

non-null Array of any type A copy of the contents of this collaborative list.

clear()

Removes all values from the list.

get(index) → any type

Gets the value at the given index.

Parameter

Name Type Optional Description

index

number

 

The index.

Returns

any type The value at the given index.

id()

The id of this collaborative object. Read-only.

Inherited from
gapi.drive.realtime.CollaborativeObject#id

indexOf(value, opt_comparatorFn) → number

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

Parameters

Name Type Optional Description

value

any type

 

The value to find.

opt_comparatorFn

function(any type, any type)

 

Optional comparator function used to determine the equality of two items.

Value must not be null.

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

Name Type Optional Description

index

number

 

The index to insert at.

value

any type

 

The value to add.

insertAll(index, values)

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

Parameters

Name Type Optional Description

index

number

 

The index at which to insert.

values

Array of any type

 

The values to insert.

Value must not be null.

lastIndexOf(value, opt_comparatorFn) → number

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

Parameters

Name Type Optional Description

value

any type

 

The value to find.

opt_comparatorFn

function(any type, any type)

 

Optional comparator function used to determine the equality of two items.

Value must not be null.

Returns

number The index of the given value, or -1 if it cannot be found.

move(index, destinationIndex)

Moves a single element in this list (at index) to immediately before destinationIndex. Both indices are with respect to the position of elements before the move.

For example, given the list: ['A', 'B', 'C']

  • move(0, 0) is a no-op
  • move(0, 1) is a no-op
  • move(0, 2) yields ['B', 'A', 'C'] ('A' is moved to immediately before 'C')
  • move(0, 3) yields ['B', 'C', 'A'] ('A' is moved to immediately before an imaginary element after the list end)
  • move(1, 0) yields ['B', 'A', 'C'] ('B' is moved to immediately before 'A')
  • move(1, 1) is a no-op
  • move(1, 2) is a no-op
  • move(1, 3) yields ['A', 'C', 'B'] ('B' is moved to immediately before an imaginary element after the list end)

Parameters

Name Type Optional Description

index

number

 

The index of the element to move.

destinationIndex

number

 

The index to move the element to. The element will be inserted immediately before this index.

moveToList(index, destination, destinationIndex)

Moves a single element in this list (at index) to immediately before destinationIndex in the list destination. Both indices are with respect to the position of elements before the move.

If the provided destination is this list, this function is identical to move(index, destinationIndex).

Parameters

Name Type Optional Description

index

number

 

The index of the element to move.

destination

gapi.drive.realtime.CollaborativeList

 

The list to move the element to.

Value must not be null.

destinationIndex

number

 

The index to move the element to. The element will be inserted immediately before this index.

push(value) → number

Adds an item to the end of the list.

Parameter

Name Type Optional Description

value

any type

 

The value to add.

Returns

number The new array length.

pushAll(values)

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

Parameter

Name Type Optional Description

values

Array of any type

 

The values to add.

Value must not be null.

registerReference(index, deleteMode) → gapi.drive.realtime.IndexReference

Creates an IndexReference pointing at the given index in this list.

Parameters

Name Type Optional Description

index

number

 

The index of the referenced element in this list.

deleteMode

gapi.drive.realtime.IndexReference.DeleteMode

 

The shift behavior of the registered reference when the element it points at is deleted. For compatibility with legacy applications, false is equivalent to DeleteMode.SHIFT_AFTER_DELETE and true is equivalent to DeleteMode.SHIFT_TO_INVALID for this parameter; new applications should use one of the DeleteMode constants instead.

Returns

non-null gapi.drive.realtime.IndexReference The newly registered reference.

remove(index)

Removes the item at the given index from the list.

Parameter

Name Type Optional Description

index

number

 

The index of the item to remove.

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

removeRange(startIndex, endIndex)

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

Parameters

Name Type Optional Description

startIndex

number

 

The start index of the range to remove (inclusive).

endIndex

number

 

The end index of the range to remove (exclusive).

removeValue(value) → boolean

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

Parameter

Name Type Optional Description

value

any type

 

The 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

Name Type Optional Description

index

number

 

The index to set at.

values

Array of any type

 

The values to insert.

Value must not be null.

set(index, value)

Sets the item at the given index

Parameters

Name Type Optional Description

index

number

 

The index to insert at.

value

any type

 

The value to set.

toString() → string

Returns a string representation of this collaborative object.

Inherited from
gapi.drive.realtime.CollaborativeObject#toString
Returns

string A string representation.

type()

The type of this collaborative object. For standard collaborative objects, see gapi.drive.realtime.CollaborrativeType for possible values; for custom collaborative objects, this value is application-defined.

Inherited from
gapi.drive.realtime.CollaborativeObject#type

Send feedback about...

Realtime API