A dynamically filled array. A SparseArray makes it easy for you to create very large arrays of data but then to defer actually populating that array until it is actually needed. This is often much faster than generating an array up front and paying the cost to load your data then.
Most of the time, you will use a SparseArray to incrementally load data from the server. For example, if you have a contact list with 3,000 contacts in it, you may create a SparseArray with a length of 3,000 and set that as the content for a ListView. As the ListView tries to display the visible contacts, it will request them from the SparseArray, which will in turn notify your delegate, giving you a chance to load the contact data from the server.
Defined in: sparse_array.js
- SproutCore 1.0
- objectAt(idx, omitMaterializing)
- provideObjectAtIndex(index, the)
- provideObjectsInRange(range, array)
- replace(idx, amt, objects)
Field DetailrangeWindowSize Number
The minimum range of elements that should be requested from the delegate. If this value is set to larger than 1, then the sparse array will always fit a requested index into a range of this size and request it.
This array contains all the start_indexes of ranges requested. This is to
sparseArrayDidRequestRange to often. Indexes are removed and
added as range requests are completed.
Class Method Detail
Convenience metohd returns a new sparse array with a default length already provided.
- len Number
- the length of the array
Instance Method Detail
Returns the set of indexes that are currently defined on the sparse array. If you pass an optional index set, the search will be limited to only those indexes. Otherwise this method will return an index set containing all of the defined indexes. Currently this can be quite expensive if you have a lot of indexes defined.
Optimized version of
indexOf(). Asks the delegate to provide the index
of the specified object. If the delegate does not implement this method
then it will search the internal array directly.
- obj Object
- the object to search for
- the discovered index or -1 if not found
Make sure to create the index array during init so that it is not shared between all instances.
The length of the sparse array. The delegate for the array should set this length.
Returns the object at the specified index. If the value for the index
is currently undefined, invokes the
didRequestIndex() method to notify
omitMaterializing flag ensures that the object will not be materialized,
but it simply checks for the presence of an object at the specified index
and will return
YES (or undefined if not found). This is useful in the case
of SparseArrays, where you might NOT want to request the index to be loaded,
but simply need a shallow check to see if the position has been filled.
Invalidates the array content in the specified range. This is not the same as editing an array. Rather it will cause the array to reload the content from the delegate again when it is requested.
- the Range
Call this method from a delegate to provide a length for the sparse array. If you pass null for this property, it will essentially "reset" the array causing your delegate to be called again the next time another object requests the array length.
- length Number
- the length or null
Convenience method to provide a single object at a specified index. Under
the covers this calls
provideObjectsInRange() so you can override only
that method and this one will still work.
This method sets the content for the specified to the objects in the
passed array. If you change the way SparseArray implements its internal
tracking of objects, you should override this method along with
Array primitive edits the objects at the specified index unless the delegate rejects the change.
objectAt() whenever you request an index that has not yet been
loaded. This will possibly expand the index into a range and then invoke
an appropriate method on the delegate to request the data.
It will check if the range has been already requested.
- idx Number
- the index to retrieve
Resets the SparseArray, causing it to reload its content from the delegate again.