Ember.TrackedArray Class packages/ember-runtime/lib/system/tracked_array.js:10

An Ember.TrackedArray tracks array operations. It's useful when you want to lazily compute the indexes of items in an array after they've been shifted by subsequent operations.

Show:

Methods

Show:

ArrayOperation

(type, count, items) private

Internal data structure to represent an array operation.

Parameters:

type String
The type of the operation. One of `Ember.TrackedArray.{RETAIN, INSERT, DELETE}`
count Number
The number of items in this operation.
items Array
The items of the operation, if included. RETAIN and INSERT include their items, DELETE does not.

ArrayOperationMatch

(operation, index, split, rangeStart) private

Internal data structure used to include information when looking up operations by item index.

Parameters:

operation ArrayOperation
index Number
The index of `operation` in the array of operations.
split Boolean
Whether or not the item index searched for would require a split for a new operation type.
rangeStart Number
The index of the first item in the operation, with respect to the tracked array. The index of the last item can be computed from `rangeStart` and `operation.count`.

_findArrayOperation

(index) private

Return an ArrayOperationMatch for the operation that contains the item at index.

Parameters:

index Number
the index of the item whose operation information should be returned.

addItems

(index, newItems)

Track that newItems were added to the tracked array at index.

Parameters:

index
newItems

apply

(callback)

Apply all operations, reducing them to retain:n, for n, the number of items in the array.

callback will be called for each operation and will be passed the following arguments:

  • {array} items The items for the given operation
  • {number} offset The computed offset of the items, ie the index in the array of the first item for this operation.
  • {string} operation The type of the operation. One of Ember.TrackedArray.{RETAIN, DELETE, INSERT}

Parameters:

callback Function

removeItems

(index, count)

Track that count items were removed at index.

Parameters:

index
count