2015-01-30 01:10:49 +00:00
|
|
|
/**
|
2017-03-24 21:18:39 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
2015-03-23 22:07:33 +00:00
|
|
|
*
|
2017-03-24 21:18:39 +00:00
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
2015-01-30 01:10:49 +00:00
|
|
|
*
|
|
|
|
* @providesModule ListViewDataSource
|
|
|
|
* @flow
|
2017-06-13 05:32:58 +00:00
|
|
|
* @format
|
2015-01-30 01:10:49 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2016-03-02 12:27:13 +00:00
|
|
|
var invariant = require('fbjs/lib/invariant');
|
2016-03-02 16:26:11 +00:00
|
|
|
var isEmpty = require('isEmpty');
|
2017-09-06 10:25:01 +00:00
|
|
|
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
|
|
|
|
* found when Flow v0.54 was deployed. To see the error delete this comment and
|
|
|
|
* run Flow. */
|
2016-03-02 12:27:13 +00:00
|
|
|
var warning = require('fbjs/lib/warning');
|
2015-01-30 01:10:49 +00:00
|
|
|
|
|
|
|
function defaultGetRowData(
|
|
|
|
dataBlob: any,
|
|
|
|
sectionID: number | string,
|
2017-06-13 05:32:58 +00:00
|
|
|
rowID: number | string,
|
2015-01-30 01:10:49 +00:00
|
|
|
): any {
|
|
|
|
return dataBlob[sectionID][rowID];
|
|
|
|
}
|
|
|
|
|
|
|
|
function defaultGetSectionHeaderData(
|
|
|
|
dataBlob: any,
|
2017-06-13 05:32:58 +00:00
|
|
|
sectionID: number | string,
|
2015-01-30 01:10:49 +00:00
|
|
|
): any {
|
|
|
|
return dataBlob[sectionID];
|
|
|
|
}
|
|
|
|
|
2017-06-13 05:32:58 +00:00
|
|
|
type differType = (data1: any, data2: any) => boolean;
|
2015-01-30 01:10:49 +00:00
|
|
|
|
|
|
|
type ParamType = {
|
2016-08-09 13:32:41 +00:00
|
|
|
rowHasChanged: differType,
|
|
|
|
getRowData?: ?typeof defaultGetRowData,
|
|
|
|
sectionHeaderHasChanged?: ?differType,
|
|
|
|
getSectionHeaderData?: ?typeof defaultGetSectionHeaderData,
|
2017-06-13 05:32:58 +00:00
|
|
|
};
|
2015-01-30 01:10:49 +00:00
|
|
|
|
2015-04-06 15:38:56 +00:00
|
|
|
/**
|
|
|
|
* Provides efficient data processing and access to the
|
|
|
|
* `ListView` component. A `ListViewDataSource` is created with functions for
|
|
|
|
* extracting data from the input blob, and comparing elements (with default
|
|
|
|
* implementations for convenience). The input blob can be as simple as an
|
|
|
|
* array of strings, or an object with rows nested inside section objects.
|
|
|
|
*
|
|
|
|
* To update the data in the datasource, use `cloneWithRows` (or
|
|
|
|
* `cloneWithRowsAndSections` if you care about sections). The data in the
|
|
|
|
* data source is immutable, so you can't modify it directly. The clone methods
|
|
|
|
* suck in the new data and compute a diff for each row so ListView knows
|
|
|
|
* whether to re-render it or not.
|
|
|
|
*
|
|
|
|
* In this example, a component receives data in chunks, handled by
|
|
|
|
* `_onDataArrived`, which concats the new data onto the old data and updates the
|
|
|
|
* data source. We use `concat` to create a new array - mutating `this._data`,
|
|
|
|
* e.g. with `this._data.push(newRowData)`, would be an error. `_rowHasChanged`
|
|
|
|
* understands the shape of the row data and knows how to efficiently compare
|
|
|
|
* it.
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* getInitialState: function() {
|
2017-07-21 21:17:47 +00:00
|
|
|
* var ds = new ListView.DataSource({rowHasChanged: this._rowHasChanged});
|
2015-04-06 15:38:56 +00:00
|
|
|
* return {ds};
|
|
|
|
* },
|
|
|
|
* _onDataArrived(newData) {
|
|
|
|
* this._data = this._data.concat(newData);
|
|
|
|
* this.setState({
|
|
|
|
* ds: this.state.ds.cloneWithRows(this._data)
|
|
|
|
* });
|
|
|
|
* }
|
|
|
|
* ```
|
|
|
|
*/
|
|
|
|
|
2015-01-30 01:10:49 +00:00
|
|
|
class ListViewDataSource {
|
|
|
|
/**
|
2015-04-06 15:38:56 +00:00
|
|
|
* You can provide custom extraction and `hasChanged` functions for section
|
2015-01-30 01:10:49 +00:00
|
|
|
* headers and rows. If absent, data will be extracted with the
|
|
|
|
* `defaultGetRowData` and `defaultGetSectionHeaderData` functions.
|
|
|
|
*
|
2015-04-06 15:38:56 +00:00
|
|
|
* The default extractor expects data of one of the following forms:
|
|
|
|
*
|
|
|
|
* { sectionID_1: { rowID_1: <rowData1>, ... }, ... }
|
|
|
|
*
|
|
|
|
* or
|
|
|
|
*
|
2015-05-15 20:26:10 +00:00
|
|
|
* { sectionID_1: [ <rowData1>, <rowData2>, ... ], ... }
|
|
|
|
*
|
|
|
|
* or
|
|
|
|
*
|
2015-04-06 15:38:56 +00:00
|
|
|
* [ [ <rowData1>, <rowData2>, ... ], ... ]
|
|
|
|
*
|
|
|
|
* The constructor takes in a params argument that can contain any of the
|
|
|
|
* following:
|
|
|
|
*
|
2015-01-30 01:10:49 +00:00
|
|
|
* - getRowData(dataBlob, sectionID, rowID);
|
|
|
|
* - getSectionHeaderData(dataBlob, sectionID);
|
|
|
|
* - rowHasChanged(prevRowData, nextRowData);
|
|
|
|
* - sectionHeaderHasChanged(prevSectionData, nextSectionData);
|
|
|
|
*/
|
|
|
|
constructor(params: ParamType) {
|
|
|
|
invariant(
|
|
|
|
params && typeof params.rowHasChanged === 'function',
|
2017-06-13 05:32:58 +00:00
|
|
|
'Must provide a rowHasChanged function.',
|
2015-01-30 01:10:49 +00:00
|
|
|
);
|
|
|
|
this._rowHasChanged = params.rowHasChanged;
|
|
|
|
this._getRowData = params.getRowData || defaultGetRowData;
|
|
|
|
this._sectionHeaderHasChanged = params.sectionHeaderHasChanged;
|
|
|
|
this._getSectionHeaderData =
|
|
|
|
params.getSectionHeaderData || defaultGetSectionHeaderData;
|
|
|
|
|
|
|
|
this._dataBlob = null;
|
|
|
|
this._dirtyRows = [];
|
|
|
|
this._dirtySections = [];
|
|
|
|
this._cachedRowCount = 0;
|
|
|
|
|
|
|
|
// These two private variables are accessed by outsiders because ListView
|
|
|
|
// uses them to iterate over the data in this class.
|
|
|
|
this.rowIdentities = [];
|
|
|
|
this.sectionIdentities = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-04-06 15:38:56 +00:00
|
|
|
* Clones this `ListViewDataSource` with the specified `dataBlob` and
|
2015-12-15 17:08:39 +00:00
|
|
|
* `rowIdentities`. The `dataBlob` is just an arbitrary blob of data. At
|
2015-09-22 23:59:23 +00:00
|
|
|
* construction an extractor to get the interesting information was defined
|
2015-04-06 15:38:56 +00:00
|
|
|
* (or the default was used).
|
|
|
|
*
|
2016-06-03 13:20:18 +00:00
|
|
|
* The `rowIdentities` is a 2D array of identifiers for rows.
|
2015-04-06 15:38:56 +00:00
|
|
|
* ie. [['a1', 'a2'], ['b1', 'b2', 'b3'], ...]. If not provided, it's
|
|
|
|
* assumed that the keys of the section data are the row identities.
|
|
|
|
*
|
|
|
|
* Note: This function does NOT clone the data in this data source. It simply
|
|
|
|
* passes the functions defined at construction to a new data source with
|
|
|
|
* the data specified. If you wish to maintain the existing data you must
|
|
|
|
* handle merging of old and new data separately and then pass that into
|
|
|
|
* this function as the `dataBlob`.
|
|
|
|
*/
|
2017-06-13 05:32:58 +00:00
|
|
|
cloneWithRows(
|
|
|
|
dataBlob: $ReadOnlyArray<any> | {+[key: string]: any},
|
|
|
|
rowIdentities: ?$ReadOnlyArray<string>,
|
|
|
|
): ListViewDataSource {
|
2017-04-11 19:17:06 +00:00
|
|
|
var rowIds = rowIdentities ? [[...rowIdentities]] : null;
|
2015-01-30 01:10:49 +00:00
|
|
|
if (!this._sectionHeaderHasChanged) {
|
|
|
|
this._sectionHeaderHasChanged = () => false;
|
|
|
|
}
|
|
|
|
return this.cloneWithRowsAndSections({s1: dataBlob}, ['s1'], rowIds);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-04-06 15:38:56 +00:00
|
|
|
* This performs the same function as the `cloneWithRows` function but here
|
|
|
|
* you also specify what your `sectionIdentities` are. If you don't care
|
|
|
|
* about sections you should safely be able to use `cloneWithRows`.
|
2015-01-30 01:10:49 +00:00
|
|
|
*
|
2017-07-21 21:17:47 +00:00
|
|
|
* `sectionIdentities` is an array of identifiers for sections.
|
|
|
|
* ie. ['s1', 's2', ...]. The identifiers should correspond to the keys or array indexes
|
|
|
|
* of the data you wish to include. If not provided, it's assumed that the
|
2015-04-06 15:38:56 +00:00
|
|
|
* keys of dataBlob are the section identities.
|
2015-01-30 01:10:49 +00:00
|
|
|
*
|
|
|
|
* Note: this returns a new object!
|
2017-07-21 21:17:47 +00:00
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* const dataSource = ds.cloneWithRowsAndSections({
|
|
|
|
* addresses: ['row 1', 'row 2'],
|
|
|
|
* phone_numbers: ['data 1', 'data 2'],
|
|
|
|
* }, ['phone_numbers']);
|
|
|
|
* ```
|
2015-01-30 01:10:49 +00:00
|
|
|
*/
|
|
|
|
cloneWithRowsAndSections(
|
2017-06-13 05:32:58 +00:00
|
|
|
dataBlob: any,
|
|
|
|
sectionIdentities: ?Array<string>,
|
|
|
|
rowIdentities: ?Array<Array<string>>,
|
2015-01-30 01:10:49 +00:00
|
|
|
): ListViewDataSource {
|
|
|
|
invariant(
|
|
|
|
typeof this._sectionHeaderHasChanged === 'function',
|
2017-06-13 05:32:58 +00:00
|
|
|
'Must provide a sectionHeaderHasChanged function with section data.',
|
2015-01-30 01:10:49 +00:00
|
|
|
);
|
2016-03-15 19:13:34 +00:00
|
|
|
invariant(
|
2017-06-13 05:32:58 +00:00
|
|
|
!sectionIdentities ||
|
|
|
|
!rowIdentities ||
|
|
|
|
sectionIdentities.length === rowIdentities.length,
|
|
|
|
'row and section ids lengths must be the same',
|
2016-03-15 19:13:34 +00:00
|
|
|
);
|
|
|
|
|
2015-01-30 01:10:49 +00:00
|
|
|
var newSource = new ListViewDataSource({
|
|
|
|
getRowData: this._getRowData,
|
|
|
|
getSectionHeaderData: this._getSectionHeaderData,
|
|
|
|
rowHasChanged: this._rowHasChanged,
|
|
|
|
sectionHeaderHasChanged: this._sectionHeaderHasChanged,
|
|
|
|
});
|
|
|
|
newSource._dataBlob = dataBlob;
|
|
|
|
if (sectionIdentities) {
|
|
|
|
newSource.sectionIdentities = sectionIdentities;
|
|
|
|
} else {
|
|
|
|
newSource.sectionIdentities = Object.keys(dataBlob);
|
|
|
|
}
|
|
|
|
if (rowIdentities) {
|
|
|
|
newSource.rowIdentities = rowIdentities;
|
|
|
|
} else {
|
|
|
|
newSource.rowIdentities = [];
|
2017-06-13 05:32:58 +00:00
|
|
|
newSource.sectionIdentities.forEach(sectionID => {
|
2015-01-30 01:10:49 +00:00
|
|
|
newSource.rowIdentities.push(Object.keys(dataBlob[sectionID]));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
newSource._cachedRowCount = countRows(newSource.rowIdentities);
|
|
|
|
|
|
|
|
newSource._calculateDirtyArrays(
|
|
|
|
this._dataBlob,
|
|
|
|
this.sectionIdentities,
|
2017-06-13 05:32:58 +00:00
|
|
|
this.rowIdentities,
|
2015-01-30 01:10:49 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
return newSource;
|
|
|
|
}
|
|
|
|
|
2017-07-21 21:17:47 +00:00
|
|
|
/**
|
|
|
|
* Returns the total number of rows in the data source.
|
|
|
|
*
|
|
|
|
* If you are specifying the rowIdentities or sectionIdentities, then `getRowCount` will return the number of rows in the filtered data source.
|
|
|
|
*/
|
2015-01-30 01:10:49 +00:00
|
|
|
getRowCount(): number {
|
|
|
|
return this._cachedRowCount;
|
|
|
|
}
|
|
|
|
|
2017-07-21 21:17:47 +00:00
|
|
|
/**
|
|
|
|
* Returns the total number of rows in the data source (see `getRowCount` for how this is calculated) plus the number of sections in the data.
|
|
|
|
*
|
|
|
|
* If you are specifying the rowIdentities or sectionIdentities, then `getRowAndSectionCount` will return the number of rows & sections in the filtered data source.
|
|
|
|
*/
|
2016-03-15 19:13:34 +00:00
|
|
|
getRowAndSectionCount(): number {
|
2017-06-13 05:32:58 +00:00
|
|
|
return this._cachedRowCount + this.sectionIdentities.length;
|
2016-03-15 19:13:34 +00:00
|
|
|
}
|
|
|
|
|
2015-01-30 01:10:49 +00:00
|
|
|
/**
|
|
|
|
* Returns if the row is dirtied and needs to be rerendered
|
|
|
|
*/
|
2017-06-13 05:32:58 +00:00
|
|
|
rowShouldUpdate(sectionIndex: number, rowIndex: number): boolean {
|
2015-01-30 01:10:49 +00:00
|
|
|
var needsUpdate = this._dirtyRows[sectionIndex][rowIndex];
|
2017-06-13 05:32:58 +00:00
|
|
|
warning(
|
|
|
|
needsUpdate !== undefined,
|
|
|
|
'missing dirtyBit for section, row: ' + sectionIndex + ', ' + rowIndex,
|
|
|
|
);
|
2015-01-30 01:10:49 +00:00
|
|
|
return needsUpdate;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the data required to render the row.
|
|
|
|
*/
|
|
|
|
getRowData(sectionIndex: number, rowIndex: number): any {
|
|
|
|
var sectionID = this.sectionIdentities[sectionIndex];
|
|
|
|
var rowID = this.rowIdentities[sectionIndex][rowIndex];
|
|
|
|
warning(
|
|
|
|
sectionID !== undefined && rowID !== undefined,
|
2017-06-13 05:32:58 +00:00
|
|
|
'rendering invalid section, row: ' + sectionIndex + ', ' + rowIndex,
|
2015-01-30 01:10:49 +00:00
|
|
|
);
|
|
|
|
return this._getRowData(this._dataBlob, sectionID, rowID);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-03-18 22:57:49 +00:00
|
|
|
* Gets the rowID at index provided if the dataSource arrays were flattened,
|
|
|
|
* or null of out of range indexes.
|
2015-01-30 01:10:49 +00:00
|
|
|
*/
|
2015-03-18 22:57:49 +00:00
|
|
|
getRowIDForFlatIndex(index: number): ?string {
|
2015-01-30 01:10:49 +00:00
|
|
|
var accessIndex = index;
|
|
|
|
for (var ii = 0; ii < this.sectionIdentities.length; ii++) {
|
|
|
|
if (accessIndex >= this.rowIdentities[ii].length) {
|
|
|
|
accessIndex -= this.rowIdentities[ii].length;
|
|
|
|
} else {
|
|
|
|
return this.rowIdentities[ii][accessIndex];
|
|
|
|
}
|
|
|
|
}
|
2015-03-18 22:57:49 +00:00
|
|
|
return null;
|
2015-01-30 01:10:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-03-18 22:57:49 +00:00
|
|
|
* Gets the sectionID at index provided if the dataSource arrays were flattened,
|
|
|
|
* or null for out of range indexes.
|
2015-01-30 01:10:49 +00:00
|
|
|
*/
|
2015-03-18 22:57:49 +00:00
|
|
|
getSectionIDForFlatIndex(index: number): ?string {
|
2015-01-30 01:10:49 +00:00
|
|
|
var accessIndex = index;
|
|
|
|
for (var ii = 0; ii < this.sectionIdentities.length; ii++) {
|
|
|
|
if (accessIndex >= this.rowIdentities[ii].length) {
|
|
|
|
accessIndex -= this.rowIdentities[ii].length;
|
|
|
|
} else {
|
|
|
|
return this.sectionIdentities[ii];
|
|
|
|
}
|
|
|
|
}
|
2015-03-18 22:57:49 +00:00
|
|
|
return null;
|
2015-01-30 01:10:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an array containing the number of rows in each section
|
|
|
|
*/
|
|
|
|
getSectionLengths(): Array<number> {
|
|
|
|
var results = [];
|
|
|
|
for (var ii = 0; ii < this.sectionIdentities.length; ii++) {
|
|
|
|
results.push(this.rowIdentities[ii].length);
|
|
|
|
}
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns if the section header is dirtied and needs to be rerendered
|
|
|
|
*/
|
2017-06-13 05:32:58 +00:00
|
|
|
sectionHeaderShouldUpdate(sectionIndex: number): boolean {
|
2015-01-30 01:10:49 +00:00
|
|
|
var needsUpdate = this._dirtySections[sectionIndex];
|
2017-06-13 05:32:58 +00:00
|
|
|
warning(
|
|
|
|
needsUpdate !== undefined,
|
|
|
|
'missing dirtyBit for section: ' + sectionIndex,
|
|
|
|
);
|
2015-01-30 01:10:49 +00:00
|
|
|
return needsUpdate;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the data required to render the section header
|
|
|
|
*/
|
|
|
|
getSectionHeaderData(sectionIndex: number): any {
|
|
|
|
if (!this._getSectionHeaderData) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
var sectionID = this.sectionIdentities[sectionIndex];
|
2017-06-13 05:32:58 +00:00
|
|
|
warning(
|
|
|
|
sectionID !== undefined,
|
|
|
|
'renderSection called on invalid section: ' + sectionIndex,
|
|
|
|
);
|
2015-01-30 01:10:49 +00:00
|
|
|
return this._getSectionHeaderData(this._dataBlob, sectionID);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Private members and methods.
|
|
|
|
*/
|
|
|
|
|
|
|
|
_getRowData: typeof defaultGetRowData;
|
|
|
|
_getSectionHeaderData: typeof defaultGetSectionHeaderData;
|
|
|
|
_rowHasChanged: differType;
|
|
|
|
_sectionHeaderHasChanged: ?differType;
|
|
|
|
|
|
|
|
_dataBlob: any;
|
2017-06-13 05:32:58 +00:00
|
|
|
_dirtyRows: Array<Array<boolean>>;
|
|
|
|
_dirtySections: Array<boolean>;
|
2015-01-30 01:10:49 +00:00
|
|
|
_cachedRowCount: number;
|
|
|
|
|
|
|
|
// These two 'protected' variables are accessed by ListView to iterate over
|
|
|
|
// the data in this class.
|
|
|
|
rowIdentities: Array<Array<string>>;
|
|
|
|
sectionIdentities: Array<string>;
|
|
|
|
|
|
|
|
_calculateDirtyArrays(
|
|
|
|
prevDataBlob: any,
|
|
|
|
prevSectionIDs: Array<string>,
|
2017-06-13 05:32:58 +00:00
|
|
|
prevRowIDs: Array<Array<string>>,
|
2015-01-30 01:10:49 +00:00
|
|
|
): void {
|
|
|
|
// construct a hashmap of the existing (old) id arrays
|
|
|
|
var prevSectionsHash = keyedDictionaryFromArray(prevSectionIDs);
|
|
|
|
var prevRowsHash = {};
|
|
|
|
for (var ii = 0; ii < prevRowIDs.length; ii++) {
|
|
|
|
var sectionID = prevSectionIDs[ii];
|
|
|
|
warning(
|
|
|
|
!prevRowsHash[sectionID],
|
2017-06-13 05:32:58 +00:00
|
|
|
'SectionID appears more than once: ' + sectionID,
|
2015-01-30 01:10:49 +00:00
|
|
|
);
|
|
|
|
prevRowsHash[sectionID] = keyedDictionaryFromArray(prevRowIDs[ii]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// compare the 2 identity array and get the dirtied rows
|
|
|
|
this._dirtySections = [];
|
|
|
|
this._dirtyRows = [];
|
|
|
|
|
|
|
|
var dirty;
|
|
|
|
for (var sIndex = 0; sIndex < this.sectionIdentities.length; sIndex++) {
|
|
|
|
var sectionID = this.sectionIdentities[sIndex];
|
|
|
|
// dirty if the sectionHeader is new or _sectionHasChanged is true
|
|
|
|
dirty = !prevSectionsHash[sectionID];
|
|
|
|
var sectionHeaderHasChanged = this._sectionHeaderHasChanged;
|
|
|
|
if (!dirty && sectionHeaderHasChanged) {
|
|
|
|
dirty = sectionHeaderHasChanged(
|
|
|
|
this._getSectionHeaderData(prevDataBlob, sectionID),
|
2017-06-13 05:32:58 +00:00
|
|
|
this._getSectionHeaderData(this._dataBlob, sectionID),
|
2015-01-30 01:10:49 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
this._dirtySections.push(!!dirty);
|
|
|
|
|
|
|
|
this._dirtyRows[sIndex] = [];
|
2017-06-13 05:32:58 +00:00
|
|
|
for (
|
|
|
|
var rIndex = 0;
|
|
|
|
rIndex < this.rowIdentities[sIndex].length;
|
|
|
|
rIndex++
|
|
|
|
) {
|
2015-01-30 01:10:49 +00:00
|
|
|
var rowID = this.rowIdentities[sIndex][rIndex];
|
|
|
|
// dirty if the section is new, row is new or _rowHasChanged is true
|
|
|
|
dirty =
|
|
|
|
!prevSectionsHash[sectionID] ||
|
|
|
|
!prevRowsHash[sectionID][rowID] ||
|
|
|
|
this._rowHasChanged(
|
|
|
|
this._getRowData(prevDataBlob, sectionID, rowID),
|
2017-06-13 05:32:58 +00:00
|
|
|
this._getRowData(this._dataBlob, sectionID, rowID),
|
2015-01-30 01:10:49 +00:00
|
|
|
);
|
|
|
|
this._dirtyRows[sIndex].push(!!dirty);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function countRows(allRowIDs) {
|
|
|
|
var totalRows = 0;
|
|
|
|
for (var sectionIdx = 0; sectionIdx < allRowIDs.length; sectionIdx++) {
|
|
|
|
var rowIDs = allRowIDs[sectionIdx];
|
|
|
|
totalRows += rowIDs.length;
|
|
|
|
}
|
|
|
|
return totalRows;
|
|
|
|
}
|
|
|
|
|
|
|
|
function keyedDictionaryFromArray(arr) {
|
|
|
|
if (isEmpty(arr)) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
var result = {};
|
|
|
|
for (var ii = 0; ii < arr.length; ii++) {
|
|
|
|
var key = arr[ii];
|
|
|
|
warning(!result[key], 'Value appears more than once in array: ' + key);
|
|
|
|
result[key] = true;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = ListViewDataSource;
|