@infinite-list/data-model
Advanced tools
Comparing version 0.2.45-recycle-group.11 to 0.2.45-recycle-group.12
@@ -8,8 +8,8 @@ import Batchinator from '@x-oasis/batchinator'; | ||
import ViewabilityConfigTuples from './viewable/ViewabilityConfigTuples'; | ||
import { InspectingAPI, InspectingListener, ItemLayout, ListDimensionsProps, ListGroupDimensionsProps, ListRangeResult, ListRenderState, OnEndReached, ScrollMetrics, StateListener, ListGroupData, ItemsDimensionsProps } from './types'; | ||
import { ItemLayout, ListDimensionsProps, ListGroupDimensionsProps, ListRangeResult, ListRenderState, OnEndReached, ScrollMetrics, StateListener, ListGroupData, ItemsDimensionsProps } from './types'; | ||
import EnabledSelector from './utils/EnabledSelector'; | ||
import OnEndReachedHelper from './viewable/OnEndReachedHelper'; | ||
import ListProvider from './ListProvider'; | ||
import Inspector from './Inspector'; | ||
declare class ListGroupDimensions<ItemT extends {} = {}> extends BaseLayout implements ListProvider { | ||
indexKeys: Array<string>; | ||
private _selector; | ||
@@ -31,5 +31,2 @@ itemToDimensionMap: WeakMap<any, any>; | ||
recalculateDimensionsIntervalTreeBatchinator: Batchinator; | ||
private _heartBeatingIndexKeys; | ||
private _heartBeatResolveChangedBatchinator; | ||
private _inspectingListener; | ||
private _flattenData; | ||
@@ -39,7 +36,2 @@ private _rangeResult; | ||
private _dimensionsIntervalTree; | ||
private registeredKeys; | ||
private _inspectingTimes; | ||
private _inspectingTime; | ||
private _heartBeatingIndexKeysSentCommit; | ||
private _startInspectBatchinator; | ||
private _listBaseDimension; | ||
@@ -49,8 +41,10 @@ private _reflowItemsLength; | ||
private _removeList; | ||
private _inspector; | ||
constructor(props: ListGroupDimensionsProps); | ||
get selector(): EnabledSelector; | ||
get inspector(): Inspector; | ||
get indexKeys(): string[]; | ||
ensureDimension(): void; | ||
cleanup(): void; | ||
getOnEndReachedHelper(): OnEndReachedHelper; | ||
getIndexKeys(): string[]; | ||
getDimension(key: string): ListDimensions<{}> | Dimension; | ||
@@ -94,4 +88,2 @@ getRenderState(): ListRenderState; | ||
getDimensionStartIndex(listKey: string, ignoreDimension?: boolean): number; | ||
pushIndexKey(listKey: string): void; | ||
getListIndex(listKey: string): number; | ||
removeListDimensions(listKey: string): void; | ||
@@ -102,2 +94,3 @@ registerList(listKey: string, listDimensionsProps: Omit<ListDimensionsProps<ItemT>, 'id'>): { | ||
}; | ||
onIndexKeysChanged(): void; | ||
calculateDimensionsIndexRange(): void; | ||
@@ -108,10 +101,2 @@ onItemsCountChanged(useCache?: boolean): void; | ||
removeItem(key: string): void; | ||
heartBeatResolveChanged(): void; | ||
heartBeat(props: { | ||
listKey: string; | ||
inspectingTime: number; | ||
}): void; | ||
getInspectAPI(): InspectingAPI; | ||
startInspection(): void; | ||
addStartInspectingHandler(cb: InspectingListener): void; | ||
registerItem(key: string, itemDimensionsProps?: Omit<ItemsDimensionsProps, 'id'>): { | ||
@@ -123,3 +108,2 @@ dimensions: Dimension; | ||
reflowFlattenData(): ListGroupData[]; | ||
updateFlattenData(listKey: string, data: any): void; | ||
getItemKey(): void; | ||
@@ -126,0 +110,0 @@ getKeyItem(): void; |
@@ -6,1 +6,2 @@ export * from './Dimensions.types'; | ||
export * from './Recycler.types'; | ||
export * from './inspector'; |
{ | ||
"name": "@infinite-list/data-model", | ||
"version": "0.2.45-recycle-group.11", | ||
"version": "0.2.45-recycle-group.12", | ||
"files": [ | ||
@@ -28,3 +28,3 @@ "dist", | ||
"@x-oasis/omit": "^0.1.14", | ||
"@x-oasis/prefix-interval-tree": "^0.1.14", | ||
"@x-oasis/prefix-interval-tree": "^0.1.18", | ||
"@x-oasis/resolve-changed": "^0.1.14", | ||
@@ -31,0 +31,0 @@ "@x-oasis/select-value": "^0.1.14", |
import Batchinator from '@x-oasis/batchinator'; | ||
import isClamped from '@x-oasis/is-clamped'; | ||
import noop from '@x-oasis/noop'; | ||
import resolveChanged from '@x-oasis/resolve-changed'; | ||
import defaultBooleanValue from '@x-oasis/default-boolean-value'; | ||
import PrefixIntervalTree from '@x-oasis/prefix-interval-tree'; | ||
@@ -19,4 +16,2 @@ import BaseLayout from './BaseLayout'; | ||
FillingMode, | ||
InspectingAPI, | ||
InspectingListener, | ||
ItemLayout, | ||
@@ -39,2 +34,3 @@ KeysChangedType, | ||
import ListProvider from './ListProvider'; | ||
import Inspector from './Inspector'; | ||
@@ -53,3 +49,2 @@ // TODO: indexRange should be another intervalTree | ||
{ | ||
public indexKeys: Array<string> = []; | ||
private _selector = new EnabledSelector(); | ||
@@ -74,5 +69,2 @@ itemToDimensionMap: WeakMap<any, any> = new WeakMap(); | ||
public recalculateDimensionsIntervalTreeBatchinator: Batchinator; | ||
private _heartBeatingIndexKeys: Array<string> = []; | ||
private _heartBeatResolveChangedBatchinator: Batchinator; | ||
private _inspectingListener: InspectingListener; | ||
/** | ||
@@ -94,7 +86,2 @@ * _flattenData could be considered as the final data model after transform | ||
private registeredKeys: Array<string> = []; | ||
private _inspectingTimes = 0; | ||
private _inspectingTime: number = +Date.now(); | ||
private _heartBeatingIndexKeysSentCommit: Array<string> = []; | ||
private _startInspectBatchinator: Batchinator; | ||
private _listBaseDimension: ListBaseDimensions<any>; | ||
@@ -111,2 +98,4 @@ | ||
private _inspector: Inspector; | ||
constructor(props: ListGroupDimensionsProps) { | ||
@@ -163,11 +152,8 @@ super({ | ||
); | ||
// this._updateScrollMetricsWithCacheBatchinator = new Batchinator( | ||
// this.updateScrollMetricsWithCache.bind(this), | ||
// 50 | ||
// ); | ||
this._heartBeatResolveChangedBatchinator = new Batchinator( | ||
this.heartBeatResolveChanged.bind(this), | ||
50 | ||
); | ||
this._inspector = new Inspector({ | ||
owner: this, | ||
onChange: this.onIndexKeysChanged.bind(this), | ||
}); | ||
this.recalculateDimensionsIntervalTreeBatchinator = new Batchinator( | ||
@@ -177,11 +163,4 @@ this.recalculateDimensionsIntervalTree.bind(this), | ||
); | ||
// 主要用来巡检 | ||
this._startInspectBatchinator = new Batchinator( | ||
this.startInspection.bind(this), | ||
50 | ||
); | ||
this._removeList = manager.addList(this); | ||
this.heartBeat = this.heartBeat.bind(this); | ||
this.startInspection = this.startInspection.bind(this); | ||
@@ -204,2 +183,10 @@ this._listBaseDimension = new ListBaseDimensions({ | ||
get inspector() { | ||
return this._inspector; | ||
} | ||
get indexKeys() { | ||
return this._inspector.indexKeys; | ||
} | ||
ensureDimension() {} | ||
@@ -216,6 +203,2 @@ | ||
getIndexKeys() { | ||
return this.indexKeys; | ||
} | ||
getDimension(key: string) { | ||
@@ -511,29 +494,8 @@ return this.keyToListDimensionsMap.get(key); | ||
pushIndexKey(listKey: string) { | ||
this.indexKeys.push(listKey); | ||
} | ||
getListIndex(listKey: string) { | ||
return this.indexKeys.findIndex((indexKey) => indexKey === listKey); | ||
} | ||
removeListDimensions(listKey: string) { | ||
const index = this.indexKeys.findIndex((indexKey) => indexKey === listKey); | ||
if (index !== -1) { | ||
const dimension = this.getDimension(listKey); | ||
dimension.getData().forEach((item) => { | ||
const index = this._flattenData.findIndex((v) => v === item); | ||
if (index !== -1) this._flattenData.splice(index, 1); | ||
}); | ||
this.indexKeys.splice(index, 1); | ||
this._dimensionsIntervalTree.remove(index); | ||
this.deleteDimension(listKey); | ||
// this.onItemsCountChanged(); | ||
this.calculateDimensionsIndexRange(); | ||
this.calculateReflowItemsLength(); | ||
this.updateChildDimensionsOffsetInContainer(); | ||
this.reflowFlattenData() | ||
this.updateScrollMetrics(this._scrollMetrics, { useCache: false }); | ||
this.inspector.remove(listKey); | ||
} | ||
@@ -563,5 +525,3 @@ } | ||
// should update indexKeys first !!! | ||
// this.pushIndexKey(listKey); | ||
this.startInspection() | ||
const { recyclerType, data = [] } = listDimensionsProps | ||
const { recyclerType } = listDimensionsProps; | ||
const dimensions = new ListDimensions({ | ||
@@ -575,28 +535,16 @@ ...listDimensionsProps, | ||
}); | ||
this._listBaseDimension.addBuffer(recyclerType) | ||
this._listBaseDimension.addBuffer(recyclerType); | ||
this.setDimension(listKey, dimensions); | ||
this.setListData(listKey, data) | ||
this._inspector.push(listKey); | ||
let onEndReachedCleaner = null | ||
// this.setListData(listKey, data); | ||
let onEndReachedCleaner = null; | ||
if (listDimensionsProps.onEndReached) { | ||
onEndReachedCleaner = this._listBaseDimension.addOnEndReached(listDimensionsProps.onEndReached) | ||
onEndReachedCleaner = this._listBaseDimension.addOnEndReached( | ||
listDimensionsProps.onEndReached | ||
); | ||
} | ||
// this.calculateDimensionsIndexRange(); | ||
// this.calculateReflowItemsLength(); | ||
// this.updateChildDimensionsOffsetInContainer(); | ||
// this.updateFlattenData(listKey, data); | ||
// this.updateScrollMetrics(this._scrollMetrics, { useCache: false }); | ||
// this.onItemsCountChanged(); | ||
// // because Dimensions should be create first, so after initialized | ||
// // update dimensionsIntervalTree (to fix Dimensions with default layout | ||
// // such getItemLayout) | ||
// this.recalculateDimensionsIntervalTreeBatchinator.schedule(); | ||
// // this.registeredKeys.push(listKey); | ||
// this.updateFlattenData(listKey, listDimensionsProps.data); | ||
// this._startInspectBatchinator.schedule(); | ||
return { | ||
@@ -606,3 +554,3 @@ dimensions, | ||
this.removeListDimensions(listKey); | ||
if (onEndReachedCleaner) onEndReachedCleaner() | ||
if (onEndReachedCleaner) onEndReachedCleaner(); | ||
}, | ||
@@ -612,2 +560,6 @@ }; | ||
onIndexKeysChanged() { | ||
this.onItemsCountChanged(); | ||
} | ||
/** | ||
@@ -645,2 +597,3 @@ * should be run immediately... | ||
onItemsCountChanged(useCache = false) { | ||
this.reflowFlattenData(); | ||
this.calculateDimensionsIndexRange(); | ||
@@ -650,3 +603,2 @@ this.calculateReflowItemsLength(); | ||
this.updateScrollMetrics(this._scrollMetrics, { useCache }); | ||
// this._updateChildPersistanceIndicesBatchinator.schedule(); | ||
} | ||
@@ -681,119 +633,14 @@ | ||
this.calculateReflowItemsLength(); | ||
this.updateScrollMetrics() | ||
this.updateScrollMetrics(); | ||
} | ||
removeItem(key: string) { | ||
const index = this.indexKeys.findIndex((indexKey) => indexKey === key); | ||
const index = this._inspector.findIndex(key); | ||
if (index !== -1) { | ||
const dimension = this.getDimension(key); | ||
dimension.getData().forEach((item) => { | ||
const index = this._flattenData.findIndex((v) => v === item); | ||
if (index !== -1) this._flattenData.splice(index, 1); | ||
}); | ||
this.indexKeys.splice(index, 1); | ||
this._dimensionsIntervalTree.remove(index); | ||
this.deleteDimension(key); | ||
// this.onItemsCountChanged(); | ||
this.calculateDimensionsIndexRange(); | ||
this.calculateReflowItemsLength(); | ||
this.updateChildDimensionsOffsetInContainer(); | ||
this.reflowFlattenData() | ||
this.updateScrollMetrics(this._scrollMetrics, { useCache: false }); | ||
this._inspector.remove(key); | ||
} | ||
} | ||
heartBeatResolveChanged() { | ||
const nextIndexKeys = this._heartBeatingIndexKeys.slice(); | ||
// 比如说,中间发生了顺序调整;自动检测确保 | ||
if ( | ||
!resolveChanged(this._heartBeatingIndexKeys, this.indexKeys).isEqual | ||
) { | ||
// if ( | ||
// !shallowArrayEqual( | ||
// this._heartBeatingIndexKeys, | ||
// this._heartBeatingIndexKeysSentCommit | ||
// ) | ||
// ) { | ||
// this.indexKeys = nextIndexKeys; | ||
// this.onItemsCountChanged(); | ||
// this._heartBeatingIndexKeysSentCommit = this.indexKeys; | ||
// } | ||
this.indexKeys = nextIndexKeys; | ||
this.onItemsCountChanged(); | ||
this._inspectingTime += 1; | ||
/** | ||
* holdout: Attention. | ||
* To fix insert a element | ||
*/ | ||
let _data = []; | ||
for (let index = 0; index < this.indexKeys.length; index++) { | ||
const listKey = this.indexKeys[index]; | ||
const _dimensions = this.getDimension(listKey); | ||
_data = _data.concat(_dimensions.getData()); | ||
} | ||
this._flattenData = _data; | ||
this.calculateDimensionsIndexRange(); | ||
} | ||
} | ||
// register first,then inspecting | ||
heartBeat(props: { listKey: string; inspectingTime: number }) { | ||
const { listKey, inspectingTime } = props; | ||
if (inspectingTime < this._inspectingTime) return; | ||
this._heartBeatingIndexKeys.push(listKey); | ||
const indexInRegisteredKeys = this.registeredKeys.findIndex( | ||
(key) => key === listKey | ||
); | ||
if (indexInRegisteredKeys !== -1) { | ||
this.registeredKeys.splice(indexInRegisteredKeys, 1); | ||
} | ||
this.heartBeatResolveChanged() | ||
// this._heartBeatResolveChangedBatchinator.schedule(); | ||
} | ||
getInspectAPI(): InspectingAPI { | ||
return { | ||
inspectingTimes: this._inspectingTimes, | ||
inspectingTime: this._inspectingTime, | ||
heartBeat: this.heartBeat, | ||
startInspection: this.startInspection, | ||
}; | ||
} | ||
startInspection() { | ||
// this._heartBeatResolveChangedBatchinator.dispose({ | ||
// abort: true, | ||
// }); | ||
const time = +Date.now(); | ||
if (typeof this._inspectingListener === 'function') { | ||
this._inspectingTimes += 1; | ||
this._heartBeatingIndexKeys = []; | ||
this._inspectingListener.call(this, { | ||
inspectingTimes: this._inspectingTimes, | ||
inspectingTime: time, | ||
heartBeat: this.heartBeat, | ||
startInspection: this.startInspection, | ||
}); | ||
} | ||
} | ||
addStartInspectingHandler(cb: InspectingListener) { | ||
if (typeof cb === 'function') this._inspectingListener = cb; | ||
} | ||
registerItem( | ||
@@ -815,3 +662,2 @@ key: string, | ||
const beforeKey = len ? this.indexKeys[len - 1] : ''; | ||
// this.pushIndexKey(key); | ||
const startIndex = beforeKey | ||
@@ -821,3 +667,3 @@ ? this.getDimensionStartIndex(beforeKey) + | ||
: 0; | ||
const { recyclerType } = itemDimensionsProps | ||
const { recyclerType } = itemDimensionsProps; | ||
const dimensions = new Dimension({ | ||
@@ -832,18 +678,5 @@ id: key, | ||
}); | ||
this.startInspection() | ||
this.setDimension(key, dimensions); | ||
this._listBaseDimension.addBuffer(recyclerType) | ||
this.calculateDimensionsIndexRange(); | ||
this.updateChildDimensionsOffsetInContainer(); | ||
this.updateFlattenData(key, dimensions.getData()); | ||
this.updateScrollMetrics(this._scrollMetrics, { useCache: false }); | ||
// this.onItemsCountChanged(); | ||
// this.recalculateDimensionsIntervalTreeBatchinator.schedule(); | ||
// this.registeredKeys.push(key); | ||
// this.updateFlattenData(key, dimensions.getData()); | ||
// this._startInspectBatchinator.schedule(); | ||
this._listBaseDimension.addBuffer(recyclerType); | ||
this._inspector.push(key); | ||
return { | ||
@@ -863,34 +696,34 @@ dimensions, | ||
this._flattenData = this.indexKeys.reduce((acc, key) => { | ||
const dimension = this.getDimension(key) | ||
const dimension = this.getDimension(key); | ||
if (dimension) { | ||
acc = [].concat(acc, dimension.getData()) | ||
acc = [].concat(acc, dimension.getData()); | ||
} | ||
return acc | ||
}, []) | ||
return this._flattenData | ||
return acc; | ||
}, []); | ||
return this._flattenData; | ||
} | ||
/** | ||
* | ||
* @param listKey dimension key. | ||
* @param data list data or a dimension... | ||
*/ | ||
updateFlattenData(listKey: string, data: any) { | ||
const _dimensions = this.getDimension(listKey); | ||
const info = this._dimensionsIndexRange.find( | ||
({ dimensions }) => dimensions === _dimensions | ||
); | ||
if (info) { | ||
const { startIndex, endIndex } = info; | ||
const before = this._flattenData.slice(0, startIndex); | ||
const after = this._flattenData.slice(endIndex); | ||
this._flattenData = [].concat(before, data, after); | ||
if (data.length !== endIndex - startIndex) { | ||
// the flattenData | ||
this.calculateDimensionsIndexRange(); | ||
} | ||
// /** | ||
// * | ||
// * @param listKey dimension key. | ||
// * @param data list data or a dimension... | ||
// */ | ||
// updateFlattenData(listKey: string, data: any) { | ||
// const _dimensions = this.getDimension(listKey); | ||
// const info = this._dimensionsIndexRange.find( | ||
// ({ dimensions }) => dimensions === _dimensions | ||
// ); | ||
// if (info) { | ||
// const { startIndex, endIndex } = info; | ||
// const before = this._flattenData.slice(0, startIndex); | ||
// const after = this._flattenData.slice(endIndex); | ||
// this._flattenData = [].concat(before, data, after); | ||
// if (data.length !== endIndex - startIndex) { | ||
// // the flattenData | ||
// this.calculateDimensionsIndexRange(); | ||
// } | ||
// this._listBaseDimension.setData(this.getData()); | ||
} | ||
} | ||
// // this._listBaseDimension.setData(this.getData()); | ||
// } | ||
// } | ||
@@ -911,13 +744,11 @@ getItemKey() {} | ||
if ( | ||
[KeysChangedType.Add, KeysChangedType.Remove, KeysChangedType.Append].indexOf(changedType) !== | ||
-1 | ||
[ | ||
KeysChangedType.Add, | ||
KeysChangedType.Remove, | ||
KeysChangedType.Append, | ||
].indexOf(changedType) !== -1 | ||
) { | ||
this.calculateDimensionsIndexRange(); | ||
this.calculateReflowItemsLength(); | ||
this.updateChildDimensionsOffsetInContainer(); | ||
this.updateFlattenData(listKey, data); | ||
this.updateScrollMetrics(this._scrollMetrics, { useCache: false }); | ||
// this.onItemsCountChanged(false); | ||
this.onItemsCountChanged(); | ||
} else if (changedType === KeysChangedType.Reorder) { | ||
this.updateFlattenData(listKey, data); | ||
this.reflowFlattenData(); | ||
// 之所以,不能够用缓存;因为现在的判断Reorder只是看key;这个key对应的item其实 | ||
@@ -1303,11 +1134,8 @@ // 并没有看;所以它不是纯粹的shuffle;这个时候item可能发生了变化,所以是不能够用 | ||
const { | ||
isEndReached, | ||
distanceFromEnd | ||
} = state | ||
const { isEndReached, distanceFromEnd } = state; | ||
this.onEndReachedHelper.performEndReached({ | ||
isEndReached, | ||
distanceFromEnd, | ||
}); | ||
this.onEndReachedHelper.performEndReached({ | ||
isEndReached, | ||
distanceFromEnd, | ||
}); | ||
return; | ||
@@ -1386,7 +1214,4 @@ } | ||
) { | ||
this._listBaseDimension.updateScrollMetrics( | ||
_scrollMetrics, | ||
_options | ||
) | ||
this._scrollMetrics = _scrollMetrics; | ||
this._listBaseDimension.updateScrollMetrics(_scrollMetrics, _options); | ||
} | ||
@@ -1393,0 +1218,0 @@ } |
@@ -150,1 +150,7 @@ import FixedBuffer from './FixedBuffer'; | ||
export default Recycler; | ||
// const origin = [163, 168, 142, 147, 152, 173, 178, 137, 157, 162] | ||
// const target = [163, 163, 142, 147, 152, 168, 173, 137, 157] | ||
// const next = [168, 168, 142, 147, 152, 173, 178, 137, 157, 162] |
@@ -18,1 +18,2 @@ "use strict"; | ||
__exportStar(require("./Recycler.types"), exports); | ||
__exportStar(require("./IndexKeys.types"), exports); |
@@ -5,2 +5,3 @@ export * from './Dimensions.types'; | ||
export * from './onEndReachedHelper'; | ||
export * from './Recycler.types' | ||
export * from './Recycler.types'; | ||
export * from './inspector'; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
150
33960
2597222