@infinite-list/data-model
Advanced tools
Comparing version 0.2.45-recycle-group.40 to 0.2.45-recycle-group.41
@@ -13,4 +13,6 @@ import { InspectorProps, InspectingAPI, InspectingListener } from './types'; | ||
private _handleChangeBatchinator; | ||
private _updateAnchorKeysBatchinator; | ||
private _isCollecting; | ||
private _onChange; | ||
private _anchorKeys; | ||
constructor(props?: InspectorProps); | ||
@@ -27,3 +29,3 @@ get owner(): ListGroupDimensions<{}>; | ||
terminateCollection(): void; | ||
updateAnchorRange(): void; | ||
updateAnchorKeys(): void; | ||
heartBeatResolveChanged(): void; | ||
@@ -30,0 +32,0 @@ heartBeat(props: { |
@@ -26,2 +26,3 @@ import Batchinator from '@x-oasis/batchinator'; | ||
private _onUpdateDimensionItemsMetaChangeBatchinator; | ||
private _onItemsCountChangedBatchinator; | ||
recalculateDimensionsIntervalTreeBatchinator: Batchinator; | ||
@@ -28,0 +29,0 @@ private _flattenData; |
{ | ||
"name": "@infinite-list/data-model", | ||
"version": "0.2.45-recycle-group.40", | ||
"version": "0.2.45-recycle-group.41", | ||
"files": [ | ||
@@ -5,0 +5,0 @@ "dist", |
@@ -46,3 +46,3 @@ import ItemMeta from './ItemMeta'; | ||
this._recyclerType = recyclerType; | ||
this._anchorKey = anchorKey; | ||
this._anchorKey = anchorKey || id; | ||
this._selectValue = horizontal | ||
@@ -49,0 +49,0 @@ ? selectHorizontalValue |
@@ -22,4 +22,6 @@ import shallowArrayEqual from '@x-oasis/shallow-array-equal'; | ||
private _handleChangeBatchinator: Batchinator; | ||
private _updateAnchorKeysBatchinator: Batchinator; | ||
private _isCollecting = false; | ||
private _onChange: OnIndexKeysChanged; | ||
private _anchorKeys: Array<string> = []; | ||
@@ -37,2 +39,7 @@ constructor(props?: InspectorProps) { | ||
); | ||
this._updateAnchorKeysBatchinator = new Batchinator( | ||
this.updateAnchorKeys.bind(this), | ||
50 | ||
); | ||
this._onChange = onChange; | ||
@@ -54,13 +61,13 @@ this._owner = owner; | ||
push(key: string) { | ||
const location = this._anchorRange[key]; | ||
// in the middle | ||
if (location && location.endIndex < this._indexKeys.length) { | ||
this._indexKeys = this._indexKeys | ||
.slice() | ||
.splice(location.endIndex, 1, key); | ||
this.updateAnchorRange(); | ||
this.handleChange(); | ||
const anchorKey = this.owner.getFinalAnchorKey(key); | ||
// @ts-ignore | ||
const index = this._anchorKeys.findLastIndex((v) => v === anchorKey); | ||
if (index !== -1) { | ||
this._indexKeys.splice(index + 1, 0, key); | ||
this._handleChangeBatchinator.schedule(); | ||
} else { | ||
this._indexKeys.push(key); | ||
} | ||
this._updateAnchorKeysBatchinator.schedule(); | ||
this._startInspectBatchinator.schedule(); | ||
@@ -70,2 +77,18 @@ return () => { | ||
}; | ||
// const location = this._anchorRange[anchorKey]; | ||
// // in the middle | ||
// if (location && location.endIndex < this._indexKeys.length) { | ||
// this._indexKeys = this._indexKeys | ||
// .slice() | ||
// .splice(location.endIndex, 1, key); | ||
// this.updateAnchorRange(); | ||
// this.handleChange(); | ||
// } else { | ||
// this._indexKeys.push(key); | ||
// } | ||
// this._startInspectBatchinator.schedule(); | ||
// return () => { | ||
// this.remove(key); | ||
// }; | ||
} | ||
@@ -84,3 +107,3 @@ | ||
this._indexKeys.splice(index, 1); | ||
// this.handleChange(); | ||
this.updateAnchorKeys(); | ||
this._handleChangeBatchinator.schedule(); | ||
@@ -128,23 +151,27 @@ } | ||
updateAnchorRange() { | ||
this._anchorRange = this._indexKeys.reduce<AnchorRange>( | ||
(acc, cur, index) => { | ||
const anchorKey = this.owner.getFinalAnchorKey(cur); | ||
if (!anchorKey) return acc; | ||
if (acc[anchorKey]) { | ||
const endIndex = acc[anchorKey].endIndex; | ||
acc[anchorKey] = { | ||
...acc[anchorKey], | ||
endIndex: endIndex + 1, | ||
}; | ||
} else { | ||
acc[anchorKey] = { | ||
startIndex: index, | ||
endIndex: index + 1, | ||
}; | ||
} | ||
return acc; | ||
}, | ||
{} | ||
updateAnchorKeys() { | ||
this._anchorKeys = this._indexKeys.map((key) => | ||
this.owner.getFinalAnchorKey(key) | ||
); | ||
// this._anchorRange = this._indexKeys.reduce<AnchorRange>( | ||
// (acc, cur, index) => { | ||
// const anchorKey = this.owner.getFinalAnchorKey(cur); | ||
// if (!anchorKey) return acc; | ||
// if (acc[anchorKey]) { | ||
// const endIndex = acc[anchorKey].endIndex; | ||
// acc[anchorKey] = { | ||
// ...acc[anchorKey], | ||
// endIndex: endIndex + 1, | ||
// }; | ||
// } else { | ||
// acc[anchorKey] = { | ||
// startIndex: index, | ||
// endIndex: index + 1, | ||
// }; | ||
// } | ||
// return acc; | ||
// }, | ||
// {} | ||
// ); | ||
} | ||
@@ -159,3 +186,3 @@ | ||
this.handleChange(); | ||
this.updateAnchorRange(); | ||
this._updateAnchorKeysBatchinator.schedule(); | ||
this._inspectingTime += 1; | ||
@@ -162,0 +189,0 @@ } |
@@ -62,2 +62,3 @@ import Batchinator from '@x-oasis/batchinator'; | ||
private _onUpdateDimensionItemsMetaChangeBatchinator: Batchinator; | ||
private _onItemsCountChangedBatchinator: Batchinator; | ||
public recalculateDimensionsIntervalTreeBatchinator: Batchinator; | ||
@@ -135,2 +136,6 @@ /** | ||
}); | ||
this._onItemsCountChangedBatchinator = new Batchinator( | ||
this.onItemsCountChanged.bind(this), | ||
50 | ||
); | ||
@@ -513,2 +518,3 @@ this._store = createStore<ReducerResult>(); | ||
this.inspector.remove(listKey); | ||
this._onItemsCountChangedBatchinator.schedule(); | ||
} | ||
@@ -654,2 +660,3 @@ } | ||
this._inspector.remove(key); | ||
this._onItemsCountChangedBatchinator.schedule(); | ||
} | ||
@@ -727,3 +734,6 @@ } | ||
) { | ||
this.onItemsCountChanged(); | ||
// 这个得跟removeItem对应都得做个延迟,不然的话会存在一个可能性,比如替换整个list的数据, | ||
// remove callback一般会慢,如果不做延迟的话,你会发现data可能存在已经unmount的数据 | ||
// this.onItemsCountChanged(); | ||
this._onItemsCountChangedBatchinator.schedule(); | ||
} else if (changedType === KeysChangedType.Reorder) { | ||
@@ -730,0 +740,0 @@ this.reflowFlattenData(); |
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
2666071
34623